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
 
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?
Yes they are the result of a formula
 
Upvote 0

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
In that case it's probably best to use the code I've supplied, rather than ans event code.
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,456
Messages
6,124,939
Members
449,197
Latest member
k_bs

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