Hello,
Long time Excel admirer, and slowly learning/fumbling my way through macros, I'm hoping someone can help me sort this one out.
Scenario:
Teams will send me excels, with multiple sheets, and depending on the project, some sheets will be hidden as they're N/A, but I need to perform the following steps on the remaining sheets...
Step 1 - Hide specific sheets based on their name.
I managed to get this to work, using the following (dummy sheet names)...
>>> use code - tags <<< instead any indents
Step 2 - Hide specific columns based on sheet name.
I have got the below code to work (dummy sheet names), however, if Sheet 'B' was already hidden, the code breaks.
I am trying to get excel to perform simple pre-determined tasks per sheet name, but to skip those tasks if the sheet is hidden (because that sheet was N/A for this project)... hoping someone can tweak this code accordingly? (I tried playing around with 'If sheet A is visible, Then perform action... but my VBA language isn't up to scratch ha)
Combine into 1 Macro button
Not sure if I should post separately, but I'm hoping once I have the code correct for step 2, I can join that with Step 1, so I just have to hit one button and all actions happen together?
Many thanks for any help you can provide
Rox
Long time Excel admirer, and slowly learning/fumbling my way through macros, I'm hoping someone can help me sort this one out.
Scenario:
Teams will send me excels, with multiple sheets, and depending on the project, some sheets will be hidden as they're N/A, but I need to perform the following steps on the remaining sheets...
Step 1 - Hide specific sheets based on their name.
I managed to get this to work, using the following (dummy sheet names)...
>>> use code - tags <<< instead any indents
Code:
Dim wsSheet As Worksheet
For Each wsSheet In Worksheets
If wsSheet.Name = "X" Or wsSheet.Name = "Y" Or wsSheet.Name = "Z" Then
wsSheet.Visible = xlSheetHidden
End If
Next wsSheet
End Sub
Step 2 - Hide specific columns based on sheet name.
I have got the below code to work (dummy sheet names), however, if Sheet 'B' was already hidden, the code breaks.
I am trying to get excel to perform simple pre-determined tasks per sheet name, but to skip those tasks if the sheet is hidden (because that sheet was N/A for this project)... hoping someone can tweak this code accordingly? (I tried playing around with 'If sheet A is visible, Then perform action... but my VBA language isn't up to scratch ha)
Code:
Sheets("A").Select
Range("C:C,E:E,G:G,H:BK").Select
Selection.EntireColumn.Hidden = True
Columns("A:A").ColumnWidth = 70
Sheets("B").Select
Range("C:C,E:E,H:H,J:J").Select
Selection.EntireColumn.Hidden = True
Columns("A:A").ColumnWidth = 70
Sheets C, D.... I'll follow the same steps as above with slightly different instructions on which columns to hide
End Sub
Combine into 1 Macro button
Not sure if I should post separately, but I'm hoping once I have the code correct for step 2, I can join that with Step 1, so I just have to hit one button and all actions happen together?
Many thanks for any help you can provide
Rox
Last edited by a moderator: