Hello, Everyone,
I am struggling to get a macro working. I'm trying to hide columns if the entry in a particular row doesn't match the value in a specific cell. I'm really just trying to create a filter for columns in order to make using a large excel sheet easier.
I have the below:
Sub HideCols()
Dim cell As Range
For Each cell In Range("Resource")
If Range("ResourceFilter") = "All" Then
cell.EntireColumn.Hidden = False
ElseIf cell.Value = Range("ResourceFilter").Value Then
cell.EntireColumn.Hidden = False
Else
cell.EntireColumn.Hidden = True
End If
Next cell
End Sub
The named ranges "Resource" and "ResourceFilter" seem to be correctly listed in the Name manager with the Scope "Workbook". When I press the button to run the macro, the module window with the code pops up with the line I have bolded here highlighted in yellow. It doesn't seem to give me an error code but the macro does not seem to be hiding any columns even when the values in the cells in the Range "Resource" don't match the value in the "ResourceFilter" cell.
Any ideas?
Thanks in advance!
I am struggling to get a macro working. I'm trying to hide columns if the entry in a particular row doesn't match the value in a specific cell. I'm really just trying to create a filter for columns in order to make using a large excel sheet easier.
I have the below:
Sub HideCols()
Dim cell As Range
For Each cell In Range("Resource")
If Range("ResourceFilter") = "All" Then
cell.EntireColumn.Hidden = False
ElseIf cell.Value = Range("ResourceFilter").Value Then
cell.EntireColumn.Hidden = False
Else
cell.EntireColumn.Hidden = True
End If
Next cell
End Sub
The named ranges "Resource" and "ResourceFilter" seem to be correctly listed in the Name manager with the Scope "Workbook". When I press the button to run the macro, the module window with the code pops up with the line I have bolded here highlighted in yellow. It doesn't seem to give me an error code but the macro does not seem to be hiding any columns even when the values in the cells in the Range "Resource" don't match the value in the "ResourceFilter" cell.
Any ideas?
Thanks in advance!