Column Hiding based on cell value

RiciH83

New Member
Joined
Mar 24, 2009
Messages
42
Hi.

I have a formula that runs across all of row 1. What im wanting to do is hide all columns that contain #n/a in that row.

Im very new to vba and would appreciate any help with this. Its a shame there is no horizontal autofilter in excel :(

Thank you
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Hello there

You can consider:

Code:
Sub hidecolumnswitherrors()
    
    Application.ScreenUpdating = False
    Columns.EntireColumn.Hidden = False
    On Error Resume Next
    Rows(1).SpecialCells(xlCellTypeFormulas, xlErrors).EntireColumn.Hidden = True

End Sub

Every error will give rise to hiding the column, not only #N/A.
 
Upvote 0
Thank you for that,

After a bit of trial and error i just managed to get this to work.

Code:
Private Sub HideColumns()
Application.ScreenUpdating = False
Dim c As Range, rng
Set rng = Range("C1:DV1")
For Each c In rng
If c.Value = "H" Then
c.EntireColumn.Hidden = True
Else
c.EntireColumn.Hidden = False
End If
Next c
End Sub

Just replaced #n/a with a "H" for Hide.

Thank you for your help though. That will come in handy for some other things im working on
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,844
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