Coding Help for hiding columns with a Row of X

Grimm127

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

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
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).
 
Upvote 0
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.
 
Upvote 0
Solution

Forum statistics

Threads
1,212,934
Messages
6,110,760
Members
448,295
Latest member
Uzair Tahir Khan

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
Back
Top