Hide/unhide columns macro

jkopedia

New Member
Joined
Jul 12, 2018
Messages
17
I am working on an analysis spreadsheet which allows for multiple properties to be analysed or for a single property to be analysed and as part of this I have several areas where there is the option to open up additional columns for properties if needed by the user. I have a macro to unhide these columns in order from property 1 to 10, however I am looking for a macro that will allow me to hide these columns from property 10 to 1 (reverse order), but can't seem to get it right. If I reverse my unhide macro it will hide them from 1 to 10, not 10 to 1 so I'm a little stumped how to get the format I want.

Can anyone help with this? My unhide macro is below if of any use for context; Essentially, this one is unhiding the columns from L to FE, but I would like the hide function to go from FE to L
__________________________
Sub UnhideACol()
Dim HiddenRange As Range, c As Range
Dim i As Integer
Set HiddenRange = Range("L6:FE74")
For i = 5 To 1 Step -1
For Each c In HiddenRange
If c.EntireColumn.Hidden = True Then
c.EntireColumn.Hidden = False
Exit For
End If
Next c
Next
End Sub
 
Fluff; amazing, that's the ticket. Thanks for your suggestions.

Also, thanks for everyone else's suggestions as well. All your help is very much appreciated!
 
Upvote 0

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Fluff; that's the ticket! Works like a charm. Thanks for your help on this one.

Thanks to everyone else as well who helped with suggestions; very much appreciated!
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0
You're welcome.

While I have you, if I have the same parameters, but instead I am hiding sets of rows starting with the set closest to the bottom of the spreadsheet (say a range of rows from 5-200) is there a similar entry that could let me close the sets of 5 rows from bottom set to top set? Thanks!
 
Upvote 0
Try
Code:
Sub jkopedia2()
   With Range("A5:A200").SpecialCells(xlVisible)
      .Offset(.Rows.Count - 5).Resize(5).EntireRow.Hidden = True
   End With
End Sub
 
Upvote 0
You're welcome, I think my doubts helped you explain more clearly what you needed.;)
 
Upvote 0
DanteAmor; definitely assist points with helping me get out what I wanted to say!

Fluff and DanteAmor (and anyone else who may be out there), I have one more challenge I just noted in editing my s/sheet; For the add and remove codes, how do I make the cell references relative in the macro? Is this possible? In some circumstances I may have users that add or subtract cells which will impact the target cells for the hide/unhide macro's. Is there a solution to this you may know? Thanks in advance!
 
Upvote 0
Do you still want to hide/unhide 5 columns/rows at a time, but with different starting points?
 
Upvote 0
In that case how do we determine the starting point?
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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