Condition Hidden Columns

smitpau

Board Regular
Joined
Apr 2, 2020
Messages
167
Office Version
  1. 365
Platform
  1. Windows
Hi,

I'd like columns to be hidden based on the value in a certain row, basically if the value in say row 2 equals "N/A" the column should be hidden. It sounds relatively simple but would prefer a range type VBA code instead of having to type out each column one by one.

Thanks for reading.

Paul
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Hi,

I'd like columns to be hidden based on the value in a certain row, basically if the value in say row 2 equals "N/A" the column should be hidden. It sounds relatively simple but would prefer a range type VBA code instead of having to type out each column one by one.

Thanks for reading.

Paul
So if you enter "N/A" in row 2 of column A you want what other columns also hidden
So like columns 2 to 12
Do you want a Inputbox to popup asking what columns?
 
Upvote 0
Kind of so say column A,B & C said "N/A" these would be hidden but columns D&E as they are not "N/A" would still stay visible.
The Inputbox is fine as long as it's only done once, i.e. the end user would not need to select them.

Thanks
 
Upvote 0
Well if you entered NA in each column you want hidden then this could work but you earlier said:
but would prefer a range type VBA code instead of having to type out each column one by one.
 
Upvote 0
How about
VBA Code:
Sub smitpau()
   Dim Cl As Range
   
   For Each Cl In Range("A2", Cells(2, Columns.Count).End(xlToLeft))
      Cl.EntireColumn.Hidden = Cl.Value = "N/A"
   Next Cl
End Sub
 
Upvote 0
Thanks Fluff that works anyway to make that automatic, guess it just overload Excel probably as about 120 column range would be included.
 
Upvote 0
Do you have lots of formulae on that sheet?
 
Upvote 0
Thanks Fluff that works anyway to make that automatic, guess it just overload Excel probably as about 120 column range would be included.
This could be done with on sheet change event code. So if you entered NA into a certain cell in one sheet the script could hide each column you wanted but some how you would have to tell it what columns
 
Upvote 0
In that case you can turn of calculation like
VBA Code:
Sub smitpau()
   Dim Cl As Range
   
   Application.Calculation = xlCalculationManual
   For Each Cl In Range("A2", Cells(2, Columns.Count).End(xlToLeft))
      Cl.EntireColumn.Hidden = Cl.Value = "N/A"
   Next Cl
   Application.Calculation = xlCalculationAutomatic
End Sub
Are the values in row the result of a formula, or manually changed?
 
Upvote 0

Forum statistics

Threads
1,214,525
Messages
6,120,051
Members
448,940
Latest member
mdusw

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