Question : Excel Visual Basic

I have two selection boxes for users to pick two options and then run a macro that will bring back the data by auto filtering on those two values being passed.  That works fine.  The problem is that I want the user to be able to have the option to just run it based on one selection box if they don't need the other filter.  I tried having the second value pass "(All)" if it was not selected on by the user,  thinking it would  select the top option of (All) on the second filter, thus not really filtering, but it is not recognizing it.  It doesn't error, it just doesn't bring back any data as it doesn't recognize the (All) option.  Below is my code

 Dim str As String
 Dim str2 as String
 str = Range("G8").Value
 str2 = Range("G9").Value
   
    Sheets("Del Perf Raw Data (2)").Select
    Cells.Select
    Selection.ClearContents
    Range("A1").Select
    Sheets("Del Perf Raw Data").Select
    Selection.AutoFilter Field:=10, Criteria1:=str
    Selection.AutoFilter Field:=6, Criteria1:=str2

Answer : Excel Visual Basic

What about doing something where you check if a box is all.

I'm not sure if filtering on a blank value will give you what you want, but you could check if str or str2 is blank later on and adjust accordingly.

Hope this helps.

 

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
If Range("G8").Value="(All)" then
   str = ""
else
   str = Range("G8").Value
end if
If Range("G9").Value="(All)" then
   str2 = ""
else
   str2 = Range("G9").Value
end if
Random Solutions  
 
programming4us programming4us