Hi,
I have a script that searches for a specific name in the first cell of every column and hides or shows an entire column when there's a match. It works just fine while there're no filters applied to any of the columns, in which case it does nothing. How can I fix this?
————————————
Also posted here.
I have a script that searches for a specific name in the first cell of every column and hides or shows an entire column when there's a match. It works just fine while there're no filters applied to any of the columns, in which case it does nothing. How can I fix this?
Code:
Private Sub chbxProduct_Click()
Dim xRg As Range
Dim xRgUni As Range
Dim xFirstAddress As String
Dim xProduct As String
On Error Resume Next
xProduct = "Product"
If ActiveSheet.Name = "Products" Then
Set xRg = Range("A1:Z1").Find(xProduct, , xlFormulas, xlWhole, , , True)
If Not xRg Is Nothing Then
xFirstAddress = xRg.Address
Do
Set xRg = Range("A1:Z1").FindNext(xRg)
If xRgUni Is Nothing Then
Set xRgUni = xRg
Else
Set xRgUni = Application.Union(xRgUni, xRg)
End If
Loop While (Not xRg Is Nothing) And (xRg.Address <> xFirstAddress)
End If
If chbxProduct.Value = True Then
xRgUni.EntireColumn.Hidden = False
Else
xRgUni.EntireColumn.Hidden = True
End If
End If
End Sub
————————————
Also posted here.