Hi All,
I found this code and I wanted to tweak it a bit and I am hoping for your help. Below is what I have currently. In the original code (See the green font) is what was there instead of the 5 currently shown which is the row I currently have the "X" in place for this code. .
So far it works pretty good. It finds those values with "X" and keeps those columns unhidden while it hides the rest. My issue falls with the Columns Count. Most of WS's columns Start from A:AM. However, In Column AR I have a filter column that I would like to hide as well. Columns AN:AQ are empty columns. But every time I run the below it doesn't pick up and hide that AR Column. Note the first two rows are reserved for Header info. So they are pretty much empty except for the first two Columns (A1:B2). What is it that I am missing to make this code work?
Sub TEST_TEST()
Application.ScreenUpdating = False
Dim RowX As Long, x As Long, lCol As Long
Sheets("Income Statement").Select
RowX = 5
'Cells.Find("*", searchorder:=xlByRows, searchdirection:=xlPrevious).Row
lCol = ActiveSheet.Cells(1, Columns.Count).End(xlToLeft).Column
For x = 1 To lCol
If Cells(RowX, x) <> "X" Then
Columns(x).Hidden = True
Else
Columns(x).Hidden = False
End If
Next x
Application.ScreenUpdating = True
End Sub
I found this code and I wanted to tweak it a bit and I am hoping for your help. Below is what I have currently. In the original code (See the green font) is what was there instead of the 5 currently shown which is the row I currently have the "X" in place for this code. .
So far it works pretty good. It finds those values with "X" and keeps those columns unhidden while it hides the rest. My issue falls with the Columns Count. Most of WS's columns Start from A:AM. However, In Column AR I have a filter column that I would like to hide as well. Columns AN:AQ are empty columns. But every time I run the below it doesn't pick up and hide that AR Column. Note the first two rows are reserved for Header info. So they are pretty much empty except for the first two Columns (A1:B2). What is it that I am missing to make this code work?
Sub TEST_TEST()
Application.ScreenUpdating = False
Dim RowX As Long, x As Long, lCol As Long
Sheets("Income Statement").Select
RowX = 5
'Cells.Find("*", searchorder:=xlByRows, searchdirection:=xlPrevious).Row
lCol = ActiveSheet.Cells(1, Columns.Count).End(xlToLeft).Column
For x = 1 To lCol
If Cells(RowX, x) <> "X" Then
Columns(x).Hidden = True
Else
Columns(x).Hidden = False
End If
Next x
Application.ScreenUpdating = True
End Sub