Macro that will HIDE and UNHIDE columns

Chris The Rock

Active Member
Joined
Feb 24, 2002
Messages
287
I have a work book with many columns. Each column represents a new day.

Because this workbook will be used for a long time, I've had to include far more columns than I presently need, so many of the columns do not contain any data. At any one time, I'd like only 10 columns to be visible.

What I'd like to do is have a macro button that the user can click that will UNhide the next 4 columns to the right, while hiding the 4 leftmost visible columns, maintaining 10 visible columns.

I can explain this better if needed, but these are the basics.
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
This should work (its not great coding though):
Sub HideColumns()
'assumes only 10 columns are showing to begin
'hides first 4 columns
Windows(1).VisibleRange.Cells(1, 1).Select
Range(Selection, ActiveCell.Offset(0, 3)).Select
Selection.EntireColumn.Hidden = True
'unhides next 4 columns
Selection.End(xlToRight).Select
ActiveCell.Offset(0, 1).Select
Range(Selection, ActiveCell.Offset(0, 3)).Select
Selection.EntireColumn.Hidden = False
End Sub

Hope this helps.
Kind regards, Al.
 
Upvote 0
Al,
Thanks for your help. I took the basic idea from your example, and formed it into exactly what I needed.
Again, many thanks.
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,688
Members
448,978
Latest member
rrauni

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