I seem to have a collision between a solution Kevin Jones (zorvek) and Shane Devenshire helped me develop at:
http://www.experts-exchange.com/Applications/MS_Office/Excel/Q_21411490.html(Solution Title: Looking for a way to embed graphic image so that it is not visible if the row is collapsed in a data outline)
with another solution Kevin and Jim Everist helped me with at:
http://www.experts-exchange.com/Applications/MS_Office/Excel/Q_21427358.html(Solution Title: Pictures Formatted with "Move and size with cells" do NOT resize when the Row Height changes)
and another filtering sub sub I am trying to implement on the same worksheet (ShowUnusedOnly_ShowALL - I'll post below). It runs from a command button and should just toggle to either: A) filter Column C (with the Column header in C11) with a criteria of "0" and display the results or B) turn the filter off if it was on (to ShowAll), but WITHOUT unhiding rows hidden by another procedure. The issue I am having is I have to find a way to consider BOTH the criteria in this column and the criteria in the VBA-defined name variable range "KeyRangeName" developed in the HideRows sub (which basically references a variable column of data in the spreadsheet, looking for a "1" as a row marker for rows to be displayed).
With an eye towards trying to set up an AutoFilter on both the values in C12:C197 AND the same corresponding Rows in the column represented by the KeyRangeName, I tried making KeyRangeName a Public variable at the top of the ThisWorkbook module (but then got a "Compile Error: Variable not defined" on KeyRangeName in HideRows (even though it was declared as Public
), so I then tried (in HideRows) assigning KeyRangeName to a new Public variable "MyKeyRangeName" and leaving KeyRangeName as a Private variable
but that also gave me a "Compile Error: Variable not defined" on KeyRangeName, this time on "MyKeyRangeName" in HideRows, even though it was declared a Public variable at the top of the ThisWorkbook module. I don't know why that's happening - if a variable is declared as Public, why would I get these errors?
By the way, if it is useful, there is dynamically determined range called "Usage", that represents the range of cells of interest in Column C - defined as:
Usage =OFFSET('Usage Report'!$C$12,0,0,COUNTA('
Usage Report'!$C$12:$C$197),1)
I also can't seem to figure out how to set up these AutoFilter tests, especially when they involve criteria in a second column whose location is variable (depending upon the factors used to construct KeyRangeName in HideRows
)
BTW, the variable column referred to by KeyNameRange is normally hidden by virtue of a collapsed Data Outline (and I will probably supress the display of the Data Outline Symbols in the finished product ... so if either the column has to be visible (and/or the Data Outline Symbols have to be visible to make a hidden column visible) in order for the AutoFilters to work, I'll need to take that into account, too ...
In sum, the user should not have to be concerned with the rows hidden by HideRows (those are automatically determined by Excel version and screen resolution and the rows hidden by that process should not be displayed when the ShowUnusedOnly_ShowALL procedure finishes). So, there really is only 1 "Filtering" operation that needs to be performed: either A) show All rows applicable to their Excel version and screen resolution, or show only those with a "0" in C12:C197 (with both NOT showing rows NOT applicable to their Excel version and screen resolution as determined in HideRows).
Hope this is clear and someone can help me see the forest for the trees
Jeff
code follows (I have left as commented out some of the variations I have been trying but none worked):
in ThisWorkbook module:
Public MyKeyRangeName As String ' For ShowUnusedOnly_ShowAll (Usage Report module)
' Public KeyRangeName As String ' For ShowUnusedOnly_ShowAll (Usage Report module)
in Sheet3(Usage Report) module:
Public Sub HideRows()
' With assistance from Kevin Jones and Shane Devenshire at:
'
http://www.experts-exchange.com/Applications/MS_Office/Excel/Q_21411490.htmlConst SM_CXSCREEN = 0 ' Initialize horizontal screen resolution metric
Dim z As Variant ' Variable for horizontal screen resolution metric (in pixels)
Dim X As String ' Trimmed version of screen resolution variable z
Dim W As String ' Right 3 characters of X
Dim Key As String ' Variable to build key name
Dim KeyRangeName As String ' Complete Variable name
Dim cell As Range
' Declare Range names for 21 possible configurations - these names will match pre-defined
' Range names in the ws, representing columns of row markers for all 21 configuations
' (although only 1 is used in the ActiveWorkbook.Names(KeyRa
ngeName).R
efersToRan
ge property)
Dim DS2800_ As Range
Dim DS2856_ As Range
Dim DS2024_ As Range
Dim DS2152_ As Range
Dim DS2280_ As Range
Dim DS2400_ As Range
Dim DS2600_ As Range
Dim DSX800_ As Range
Dim DSX856_ As Range
Dim DSX024_ As Range
Dim DSX152_ As Range
Dim DSX280_ As Range
Dim DSX400_ As Range
Dim DSX600_ As Range
Dim DS3800_ As Range
Dim DS3856_ As Range
Dim DS3024_ As Range
Dim DS3152_ As Range
Dim DS3280_ As Range
Dim DS3400_ As Range
Dim DS3600_ As Range
z = GetSystemMetrics(SM_CXSCRE
EN) ' API call to get screen resolution in pixels
X = Trim(z) ' To trim leading and trailing spaces in z
W = Right(X, 3) ' Right 3 characters of X
If Application.Version = 9 Then
Key = "DS2"
ElseIf Application.Version = 10 Then
Key = "DSX"
ElseIf Application.Version > 10 Then
Key = "DS3"
End If
KeyRangeName = Key & Right(X, 3) & "_"
MyKeyRangeName = KeyRangeName
For Each cell In ActiveWorkbook.Names(KeyRa
ngeName).R
efersToRan
ge
If cell = 1 Then
cell.EntireRow.Hidden = False
Else
cell.EntireRow.Hidden = True
End If
Next cell
End Sub
Sub ShowUnusedOnly_ShowAll()
Dim CalculationSave As Long
CalculationSave = Application.Calculation
Application.Calculation = xlManual
Application.ScreenUpdating
= False
Range("C11").Select
'If ActiveSheet.FilterMode = True Then
With ActiveSheet
If .AutoFilterMode Then
With .AutoFilter.Filters(3)
If .On Then
GoTo TurnOFF
Else
GoTo TurnON
End If
End With
Else
GoTo TurnON
End If
End With
'If Selection.AutoFilter(Field
:=3, Criteria1:="0") = True Then
TurnOFF:
ActiveSheet.ShowAllData
HideRows ' Hide rows not applicable to this configuration
Selection.AutoFilter ' Turns Off AutoFilter Drop-down arrows
'Else
TurnON:
' Selection.AutoFilter Field:=3, Criteria1:="0", VisibleDropDown:=False
Selection.AutoFilter Field:="Usage", Criteria1:="0", Field:="KeyRangeName", Criteria2:="1", VisibleDropDown:=False
HideRows
'End If
Application.Calculation = CalculationSave
Application.ScreenUpdating
= True
End Sub