Hide/Unhide cells using macro

jkopedia

New Member
Joined
Jul 12, 2018
Messages
17
Hello,

Looking for some help on a macro I am trying to use to hide/unhide cells in excel worksheet. I am having two issues,

1. For multiple rows, say ~20, the macro is slow and choppy
2. For rows, I would like to hide from bottom to top
3. For columns, I would like to hide from right to left

The two are below, with the hide versions basically just reversing True/False. Thanks for any help or tips that can be provided!

Sub UnhideACol()
Dim HiddenRange As Range, c As Range
Dim i As Integer
Set HiddenRange = Range("J6:DY74")
For i = 4 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 i
End Sub


Sub UnhideARowl()
Dim HiddenRange As Range, c As Range
Dim i As Integer
Set HiddenRange = Range("A26:K625")
For i = 20 To 1 Step -1
For Each c In HiddenRange
If c.EntireRow.Hidden = True Then
c.EntireRow.Hidden = False
Exit For
End If
Next c
Next i
End Sub
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Not entirely sure what you are after, but these will hide if visible & vice versa
Code:
Sub UnhideACol()
   Dim i As Long
   For i = 129 To 10 Step -1
      Columns(i).Hidden = Not Columns(i).Hidden
   Next i
End Sub

Sub UnhideARowl()
   Dim i As Long
   For i = 625 To 26 Step -1
      Rows(i).Hidden = Not Rows(i).Hidden
   Next i
End Sub
 
Upvote 0
Thanks,

I have a spreadsheet where I have a set of 31 columns that are pre-populated with the formulas I need and I am looking to be able to unhide (Left to right)/hide (right to left) them as needed depending on the number of those variables I need.

The code above does hide/unhide, however can it be set to an isolated section of cells as in the originals?
 
Upvote 0
You cannot hide individual cells, only entire rows/columns
 
Upvote 0
Yes, sorry, I meant entire rows of cells. The one I have now has a Range("J:DY"), but it runs a little slow and choppy when I have larger groups of cells/rows to hide/unhide. I am wondering if there is a code outline that would perform the task faster/more smoothly than the one on my original post? Thanks for any help you can provide!

 
Upvote 0
It can definitely be made faster but you code & description do not agree.
All you code does is unhide hidden columns/rows.
Is that what you want?
 
Upvote 0
Yes, that's it. Just more efficiently than my original code and un-hide in the left to right direction and hide in the right to left direction.
 
Upvote 0
The direction is for presentation purposes. Basically, my spreadsheet is a template to analyze multiple properties at a time (up to 31) and just looking to limit or expand the view on number of properties being analyzed at any given time.
 
Upvote 0
This will unhide all columns/rows
Code:
Sub UnhideACol()
   Dim i As Long
   For i = 129 To 10 Step -1
      Columns(i).Hidden = False
   Next i
End Sub

Sub UnhideARowl()
   Dim i As Long
   For i = 625 To 26 Step -1
      Rows(i).Hidden = False
   Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,885
Messages
6,122,085
Members
449,064
Latest member
MattDRT

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