CareerChange
05-06-2011, 02:47 PM
Consider the following code snippet...
call ActivateWorksheet("someSheet")
call SetFilters(22, "someValue")
Sub ActivateWorksheet(sSheet)
If ActiveSheet.Name <> sSheet Then
Worksheets(sSheet).Activate
End If
End Sub
Sub SetFilters(nField, cCriteria)
Selection.AutoFilter Field:=nField, Criteria1:=cCriteria
End Sub
The above code snippets work just fine, however I want to avoid activating the particular worksheet, so I thought that I could do something like this...
Sub SetFilters(sSheet, nField, cCriteria)
Worksheets(sSheet).AutoFilter Field:=nField, Criteria1:=cCriteria
End Sub
Simply put, why isn't activating a particular worksheet followed by the Selection.AutoFilter functionally equivalent to straight-out referencing it using Worksheets("someSheet").AutoFilter.?
Is there an easy way to (easily) accomplish what I want w/o a ton of complex coding?
Thank you!
call ActivateWorksheet("someSheet")
call SetFilters(22, "someValue")
Sub ActivateWorksheet(sSheet)
If ActiveSheet.Name <> sSheet Then
Worksheets(sSheet).Activate
End If
End Sub
Sub SetFilters(nField, cCriteria)
Selection.AutoFilter Field:=nField, Criteria1:=cCriteria
End Sub
The above code snippets work just fine, however I want to avoid activating the particular worksheet, so I thought that I could do something like this...
Sub SetFilters(sSheet, nField, cCriteria)
Worksheets(sSheet).AutoFilter Field:=nField, Criteria1:=cCriteria
End Sub
Simply put, why isn't activating a particular worksheet followed by the Selection.AutoFilter functionally equivalent to straight-out referencing it using Worksheets("someSheet").AutoFilter.?
Is there an easy way to (easily) accomplish what I want w/o a ton of complex coding?
Thank you!