ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Hiding specific column on all worksheets (https://www.excelbanter.com/excel-programming/346508-hiding-specific-column-all-worksheets.html)

Scott Steiner

Hiding specific column on all worksheets
 
Hi,

I want to hide column A of all my worksheets. When I do this by hand
then everything is ok i.e. I select all worksheets and hide column A. So
I recorded a macro with these steps, here's the produced code:

Sub Macro2()
Sheets(Array("Sheet1", "Sheet2", "Sheet3")).Select
Sheets("Sheet1").Activate
Columns("A:A").Select
Selection.EntireColumn.Hidden = True
Sheets("Sheet1").Select
End Sub

However, when I now run the above macro, only column A of the first
sheet is hidden. What is wrong with the code?

Thanks.

Bob Phillips[_6_]

Hiding specific column on all worksheets
 
Sub Macro2()
Sheets(Array("Sheet1", "Sheet2", "Sheet3")).Select
Columns("A:A").Hidden = True
Sheets("Sheet1").Select
End Sub


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Scott Steiner" wrote in message
...
Hi,

I want to hide column A of all my worksheets. When I do this by hand
then everything is ok i.e. I select all worksheets and hide column A. So
I recorded a macro with these steps, here's the produced code:

Sub Macro2()
Sheets(Array("Sheet1", "Sheet2", "Sheet3")).Select
Sheets("Sheet1").Activate
Columns("A:A").Select
Selection.EntireColumn.Hidden = True
Sheets("Sheet1").Select
End Sub

However, when I now run the above macro, only column A of the first
sheet is hidden. What is wrong with the code?

Thanks.




Shailesh Shah[_2_]

Hiding specific column on all worksheets
 
Hi Scott,
Try this,

Sub Macro3()
Dim sht As Worksheet
For Each sht In ActiveWorkbook.Worksheets
sht.Columns("A").Hidden = True
Next
End Sub

Regards,
Shah Shailesh
http://members.lycos.co.uk/shahweb/
(Excel Add-ins)

*** Sent via Developersdex http://www.developersdex.com ***


All times are GMT +1. The time now is 12:21 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com