Delete Hidden Columns


Posted by Adrae on December 06, 2001 7:05 PM

Is there a way to write a macro to delete hidden columns? Thanks :-)

Posted by Colo on December 06, 2001 8:17 PM

Hi Adrae

Try This code.

Sub Delet_Hidden_Columns()
Dim i As Integer
For i = Cells.SpecialCells(11).Column To 1 Step -1
With Columns(i).EntireColumn
If .Hidden = True Then .Delete (xlShiftToLeft)
End With
Next
End Sub

Posted by Adrae on December 06, 2001 8:24 PM

That did it. Thank You!!!

Posted by Adrae on December 06, 2001 8:34 PM

Hello Again Colo - One adjustment to this. How would I modify this to delete these hidden columns on every sheet in the workbook without knowing the sheets' names. Thanks again.
:-) Adrae



Posted by Colo on December 06, 2001 8:53 PM

Hello Adrae! (^o^)
:How would I modify this to delete these hidden columns on every sheet
:in the workbook without knowing the sheets' names.

How to modify the code is simple.
Only loop each sheet with "For Each Next statment"
I made sample 4 u.

Sub Sample()
Dim Sh As Worksheet, i As Integer
Application.ScreenUpdating = False
For Each Sh In Worksheets
For i = 256 To 1 Step -1
With Sh.Columns(i).EntireColumn
If .Hidden = True Then .Delete (xlShiftToLeft)
End With
Next
Next
Application.ScreenUpdating = True
MsgBox "...Done!"
End Sub