hide columns

macro_panic

New Member
Joined
Mar 17, 2002
Messages
47
is there a macro genius out there who knows how to automate hiding columns in excel, please? i have a large-ish spreadsheet with many columns which may or may not be used depending on user input, and i want to hide the unused columns so they don't print / take up screen space. is it possible to hide columns dependent on the contents of cells i.e. "if cell H3 on sheet 1 is blank, hide columns F, H, and K on sheet 2"
thanks in advance
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
This should work OK for you, right-click on your sheet1 tab, select view code and paste in the following: -

Private Sub Worksheet_Change(ByVal Target As Range)

If [H3].Value = "" Then
Sheet2.Range("F:F,H:H,K:K").Columns.Hidden = True
End If

End Sub
 
Upvote 0
Actually, this might be better: -

Private Sub Worksheet_Change(ByVal Target As Range)

If [H3].Value = "" Then
Sheet2.Range("F:F,H:H,K:K").Columns.Hidden = True
Else:
Sheet2.Range("F:F,H:H,K:K").Columns.Hidden = False
End If

End Sub
 
Upvote 0
I have a similar problem in that I wish to hide a specific column based on the contents of one cell in that column.

The spreadsheet covers 12 columns, with a total column at the extreme right. Not all the columns are used every time so the total column ends up some way from the last column to be completed. I would like to find a way of formatting each column so that, if it contains no data, it is hidden.

Is it possible to write a code which applies to an individual column or do I have replicate the above code for each column in turn?

Thanks a lot,
John
 
Upvote 0

Forum statistics

Threads
1,214,573
Messages
6,120,310
Members
448,955
Latest member
Dreamz high

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