Still a VBA newbie. Please help.


Posted by Sean on June 23, 2001 4:43 AM

Sub ConditionalHide()
Dim cRange As String
cRange = Sheets("Char Dev").Range("A1")
For i = 2 To Sheets.Count
If Sheets(i).Range("A1").Value <> cRange Then
Sheets(i).Visible = False
Else: Sheets(i).Visible = True
End If
Next i
End Sub

Is it possible to run this script for more than one criteria?

I want it to show me all sheets matching criteria in A1 plus all sheets matching criteria in A2 plus all sheets matching criteria in A3.



Posted by Dax on June 23, 2001 8:12 AM

Hello,

Yes you can with something like this: -
Sub ConditionalHide()
Dim cRange1 As String, cRange2 As String, cRange3 As String
cRange1 = Sheets("Char Dev").Range("A1")
cRange2 = Sheets("Char Dev").Range("A2")
cRange3 = Sheets("Char Dev").Range("A3")

For i = 2 To Sheets.Count
With Sheets(i)
If (.Range("A1").Value = cRange1) And _
(.Range("A2").Value = cRange2) And _
(.Range("A3").Value = cRange3) Then
.Visible = True
Else
.Visible = False
End If
End With
Next i
End Sub

Regards,
Dax.