Hide Column Based on Cell Value -

jsw469

Board Regular
Joined
Oct 20, 2005
Messages
202
I did search for this and could not find one that I could try to use.

I am try to find a macro that will look at Row 2 and if there is a "N/A" in that column it will hide the column. And of couse a code to unhide as well.

Excel 2010
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
To Hide:

Code:
For i = 1 To Cells(2, Columns.Count).End(xlToLeft).Column
    If Cells(2, i) = "N/A" Then Cells(2, i).EntireColumn.Hidden = True
Next i

To unhide, you set .Hidden as False
 
Upvote 0
I did search for this and could not find one that I could try to use.

I am try to find a macro that will look at Row 2 and if there is a "N/A" in that column it will hide the column. And of couse a code to unhide as well.

Excel 2010

Does it contain the literal string "N/A" or are you trying to hide an "#N/A!" error?

Code:
Public Sub HideNAString()
Dim i As Long
For i = 2 To Cells(2, Columns.Count).End(xlToLeft).Column
    Cells(2, i).EntireColumn.Hidden = Cells(2, i).Value = "N/A"
Next i
End Sub
 
Public Sub HideNAError()
Dim i As Long
For i = 2 To Cells(2, Columns.Count).End(xlToLeft).Column
    Cells(2, i).EntireColumn.Hidden = IsError(Cells(2, i).Value)
Next i
End Sub
 
Last edited:
Upvote 0
I am doing a series of Graphs and it is a created #N/A so that the headder will not show up on the graph then I am using the hide column to remove it from the legend.
 
Upvote 0
Public Sub HideNAString()
Thsi one worked. How do I do it to unhide the Column, I am used to the =False or True but not a .hidden
 
Upvote 0
Public Sub HideNAString()
Thsi one worked. How do I do it to unhide the Column, I am used to the =False or True but not a .hidden

Code:
Public Sub UnhideAll()
Cells.EntireColumn.Hidden = False
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,845
Members
452,948
Latest member
UsmanAli786

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