Coding Help for hiding columns with a Row of X

Grimm127

Board Regular
Joined
Aug 17, 2011
Messages
118
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
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
10,311
Try:
VBA Code:
Col = ActiveSheet.Cells(5, Columns.Count).End(xlToLeft).Column
Using this code, the AR Column will be hidden if cell AR5 contains an "X".
If this doesn't work, it would be easier to help if you could use the XL2BB add-in (icon in the menu) to attach a screenshot (not a picture) of your sheet. Alternately, you could upload a copy of your file to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. Explain in detail what you want to do referring to specific cells, rows, columns and sheets using a few examples from your data (de-sensitized if necessary).
 

Grimm127

Board Regular
Joined
Aug 17, 2011
Messages
118
I found out that that X was not in caps and that was the issue. So I am good. Thank you for your reply it helped me find that error.
 
Solution

Watch MrExcel Video

Forum statistics

Threads
1,130,400
Messages
5,641,927
Members
417,247
Latest member
Chitaah

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top