happyhungarian

Active Member
Joined
Jul 19, 2011
Messages
252
Office Version
  1. 365
Platform
  1. Windows
Hi, I use the following code to unhide rows incrementally. How can I change it to unhide Columns in the same manner? Example, my hidden columns would be columns C through H

Sub Unhide_Rows()

Dim i as Long

With ActiveSheet
For i = 21 to 35
If .Rows(i).EntireRow.Hidden Then
.Rows(i).EntireRow.Hidden = False
Exit For
End If
Next i
End With

End Sub
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Code:
Option Explicit


Sub Cols()
    Dim i As Long, lc As Long
    lc = Cells(1, Columns.Count).End(xlToLeft).Column
    With ActiveSheet
        For i = 1 To lc
            If .Columns(i).EntireColumn.Hidden Then
                .Columns(i).EntireColumn.Hidden = False
            End If
        Next i
    End With
End Sub
 
Upvote 0
Thanks for replying! I'm having trouble making it work though. If my hidden columns begin at Column C do I need to set i = 3? I changed the code to the following but it would simply unhide all columns rather than doing it incrementally (example, when i run the macro it would unhide Column C, if I run it again it unhides Column D, etc)


Sub Cols()
Dim i As Long, lc As Long
lc = Cells(7, Columns.Count).End(xlToLeft).Column
With ActiveSheet
For i = 1 To lc
If .Columns(i).EntireColumn.Hidden Then
.Columns(i).EntireColumn.Hidden = False
End If
Next i
End With
End Sub
 
Last edited:
Upvote 0
Code:
Sub Cols()
  Dim iCol As Long

  For iCol = 10 To 1 Step -1 ' start wherever you like
    If Columns(i).Hidden Then
      Columns(i).Hidden = False
      Exit Sub
    End If
  Next i
End Sub
 
Upvote 0
shg I get a "Invalid Next control variable reference" error... I updated the code to say for iCol = 3 since I wanted it to start at C... was that correct?
 
Upvote 0
If you do not know the number of a column, you can refer to the letter of the column:

Code:
Sub unhide_col()
    Dim u As Long
    For i = Columns("C").Column To Columns("H").Column
        If Columns(i).Hidden Then Columns(i).Hidden = False: Exit For
    Next
End Sub
 
Last edited:
Upvote 0
If your trying to toggle column C to H from hidden to unhidden:
Try this:

Code:
Sub unhide_col()
'Modified  3/19/2019  7:47:39 PM  EDT
Columns(3).Resize(, 6).Hidden = Not Columns(3).Resize(, 6).Hidden
End Sub
 
Upvote 0
Sorry:

Code:
Sub Cols()
  Dim iCol As Long

  For iCol = 10 To 1 Step -1
    If Columns(iCol).Hidden Then
      Columns(iCol).Hidden = False
      Exit Sub
    End If
  Next iCol
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,870
Messages
6,122,021
Members
449,060
Latest member
LinusJE

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