Running same vba code on first 14 sheets

valmir

Board Regular
Joined
Feb 10, 2021
Messages
235
Office Version
  1. 365
Platform
  1. Windows
Hi Everyone!
I have this code to unhide all columns in a sheet that I need to run on the first 14 sheets of my workbooks. My workbooks have a total 16 or 17 sheets. Is there a way to run any code on the first 14 sheets at once or otherwise specify the names of those sheets that the code should not run into?
This is the code:
Sub Unhide_ColumnsRows_On_All_Sheets()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
ws.Cells.EntireColumn.Hidden = False
ws.Cells.EntireRow.Hidden = False
Next ws
End Sub

If possible, I would like a solution that can work for the first 14 and that I can edit to work with the first 16 as well (some of my worksheets the code needs to run on the first 16 sheets), otherwise, as I mentioned before, one that specifies which sheets it should not run into.
Thanks!
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
if your sheet arrangement at the bottom of workbook is the same as you want, Try this:

VBA Code:
Sub Unhide_ColumnsRows_On_All_Sheets()
Dim i as Long
For i = 1 to 14
Sheets(i).Cells.EntireColumn.Hidden = False
Sheets(i).Cells.EntireRow.Hidden = False
Next i
End Sub
 
Upvote 0
Solution
if your sheet arrangement at the bottom of workbook is the same as you want, Try this:

VBA Code:
Sub Unhide_ColumnsRows_On_All_Sheets()
Dim i as Long
For i = 1 to 14
Sheets(i).Cells.EntireColumn.Hidden = False
Sheets(i).Cells.EntireRow.Hidden = False
Next i
End Sub
When I try to run the code combination like this:
Sub Unhide_ColumnsRows_On_All_Sheets()
Dim i as Long
For i = 1 to 14
Sheets(i).Cells.EntireColumn.Hidden = False
Sheets(i).Cells.EntireRow.Hidden = False
Next i
End Sub

Sub Unhide_ColumnsRows_On_All_Sheets()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
ws.Cells.EntireColumn.Hidden = False
ws.Cells.EntireRow.Hidden = False
Next ws
End Sub
I receive this error message:
Compile error:
Ambiguous name detected: Unhide_ColumnsRows_On_All_Sheets
 
Upvote 0
You should change one of these 2 macro name. VBA can't run 2 macro with same name.
 
Upvote 0
I thought I had to run both codes.
Just one more please. I need to do the same on the first 14 sheets but the action would be inserting a column on FP, instead.
Thanks!
 
Upvote 0
Change Cells to Range("FP1") at that code:
VBA Code:
Sub UnhideColumnFP()
Dim i as Long
For i = 1 to 14
Sheets(i).Range("FP1").EntireColumn.Hidden = False
End Sub
Also if you want hide or unhide all columns, don't need to do it on rows. then you can delete entirerows lines code at all codes also.
 
Upvote 0
Both work like a charm. Thanks a lot for your time, patience and skills! :) ???
 
Upvote 0

Forum statistics

Threads
1,215,047
Messages
6,122,858
Members
449,096
Latest member
Erald

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