Macro to list the hidden columns

raghav17

New Member
Joined
Sep 4, 2016
Messages
5
Hi Guys,

I am pretty new to VBA but I cam across a macro which lists out the hidden rows in a worksheet :-

Sub ShowRows()
Dim rng As Range
Dim r As Range
Dim sTemp As String

Set rng = Range("A1:A1000")
sTemp = ""
For Each r In rng.Rows
If r.EntireRow.Hidden Then
sTemp = sTemp & "Row " & Mid(r.Address, 4) & vbCrLf
End If
Next r

If sTemp > "" Then
sTemp = "The following rows are hidden:" & vbCrLf & _
vbCrLf & sTemp
MsgBox sTemp
Else
MsgBox "There are no hidden rows"
End If
End Sub


But now I want a macro which lists out the hidden column in same way. Thanks for help in advance.
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Maybe this

Code:
Sub ShowRows()
Dim i As Variant
Dim sTemp As String
sTemp = ""
LastCol = Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByColumns, _
          SearchDirection:=xlPrevious).Column
For i = 1 To LastCol
If Columns(i).EntireColumn.Hidden Then
sTemp = sTemp & "Column " & (i) & vbCrLf
End If
Next i

If sTemp > "" Then
sTemp = "The following Columns are hidden:" & vbCrLf & _
vbCrLf & sTemp
MsgBox sTemp
Else
MsgBox "There are no hidden Columns"
End If
End Sub
 
Upvote 0
You will get that error if you have a blank sheet ??
Is the code pasted into "This Workbook" module ?
IS the sheet to be checked the active sheet ??
 
Upvote 0
I am using "This Workbook". but still unable to run the macro. You can run the Macro I provided in my very first Post and I want a list similar to that. Thanks a lot. :)
 
Upvote 0
I've run the macro I posted in Post #2, with no issues ??
Have you stepped through manually to see where the error occurs ??
 
Last edited:
Upvote 0
LastCol = Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious).Column

I am getting error in this command. You are running the macro on "Active sheet" or "This workbook"
 
Upvote 0
Can't see any reason for it not to work....but try..
AND
the code MUST be in either ThisWorkbook OR a Standard Module NOT the sheet module!!

Code:
Sub Showcolumns()
Dim i As Variant, sTemp As String
sTemp = ""
For i = 1 To ActiveSheet.Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByColumns, _
          SearchDirection:=xlPrevious).Column '16384
If Columns(i).EntireColumn.Hidden Then
sTemp = sTemp & "Column " & (i) & vbCrLf
End If
Next i
If sTemp > "" Then
sTemp = "The following Columns are hidden:" & vbCrLf & _
vbCrLf & sTemp
MsgBox sTemp
Else
MsgBox "There are no hidden Columns"
End If
End Sub
 
Last edited:
Upvote 0
Ummm, what di you mean by this...

the error was resolved when I changed the number of columns.

My code allowed for the last used column ???
 
Upvote 0

Forum statistics

Threads
1,216,126
Messages
6,129,005
Members
449,480
Latest member
yesitisasport

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