Hello,
I’m a macro/VBA rookie and I’m trying to build a macro that hides or shows columns that don’t contain multiple values or partial text strings. I’ve found and modified code that will hide or show all columns that don’t contain one value, but I’m having trouble with using a wildcard or multiple criteria.
Here’s the code I’m trying to use. The “Or” command seems to be the problem.
If I delete Or “C-PRG”, then the code works fine and shows only columns with the heading “S-PRG.”
I also tried using a wildcard but these did not work:
cl.EntireColumn.Hidden = cl <> "*PRG"
cl.EntireColumn.Hidden = cl <> "*PRG*"
In plain ‘ole English, I need the macro to hide all columns based on a cell value that don’t contain LABEL1, LABEL2, etc. (C-PRG and S-PRG in my code above.) I’d also need a macro that hides all columns based on a cell value that don’t contain a wildcard search, such as all columns whose cell reference does not contain *BEL* (I’m using BEL as an example since it is contain in the word LABEL.)
Can anyone help?
I’m a macro/VBA rookie and I’m trying to build a macro that hides or shows columns that don’t contain multiple values or partial text strings. I’ve found and modified code that will hide or show all columns that don’t contain one value, but I’m having trouble with using a wildcard or multiple criteria.
Here’s the code I’m trying to use. The “Or” command seems to be the problem.
Code:
Sub PRG_SHOW()
Columns("Q:AIG").Select
Selection.EntireColumn.Hidden = False
Dim rng As Range
Dim cl As Range
Application.ScreenUpdating = False
Set rng = [R2:AIG2]
For Each cl In rng
If IsError(cl) Then
cl.EntireColumn.Hidden = cl = CVErr(xlErrNA)
Else
cl.EntireColumn.Hidden = cl <> "S-PRG" Or "C-PRG"
End If
Next
Application.ScreenUpdating = True
Range("M1").Select
End Sub
If I delete Or “C-PRG”, then the code works fine and shows only columns with the heading “S-PRG.”
I also tried using a wildcard but these did not work:
cl.EntireColumn.Hidden = cl <> "*PRG"
cl.EntireColumn.Hidden = cl <> "*PRG*"
In plain ‘ole English, I need the macro to hide all columns based on a cell value that don’t contain LABEL1, LABEL2, etc. (C-PRG and S-PRG in my code above.) I’d also need a macro that hides all columns based on a cell value that don’t contain a wildcard search, such as all columns whose cell reference does not contain *BEL* (I’m using BEL as an example since it is contain in the word LABEL.)
Can anyone help?