|
-
Apr 27th, 2013, 09:47 AM
#1
Thread Starter
New Member
Run Macro on multiple worksheets within an excel file
Hello,
I am trying to create a macro to run on all worksheets within a tab. So far it is only running on one worksheet and it does not work on other. Can someone please assist me. Below is the code I used. Thank you
Code:
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
If ws.Name <> "Sheet1" Or ws.Name <> "Sheet2" Then
Columns("F:H").Select
Range("H1").Activate
Selection.EntireColumn.Hidden = True
End If
Next ws.Activate
End Sub
Last edited by Siddharth Rout; Apr 27th, 2013 at 01:17 PM.
Reason: Added Code Tages
-
Apr 27th, 2013, 01:16 PM
#2
Re: Run Macro on multiple worksheets within an excel file
Welcome to the forums biyi11 
Is this wihat you are trying?
Code:
Sub Sample()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
If ws.Name <> "Sheet1" Or ws.Name <> "Sheet2" Then
ws.Columns("F:H").EntireColumn.Hidden = True
End If
Next
End Sub
Last edited by Siddharth Rout; Apr 28th, 2013 at 11:04 PM.
Reason: typo fixed
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Apr 28th, 2013, 06:32 PM
#3
Thread Starter
New Member
Re: Run Macro on multiple worksheets within an excel file
Yes, but it seems not be working on all the tabs in the excel tab. Do I need an activate all worksheets statement included.
 Originally Posted by koolsid
Welcome to the forums biyi11
Is this wihat you are trying?
Code:
Sub Sample()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
If ws.Name <> "Sheet1" Or ws.Name <> "Sheet2" Then
ws.Columns("F:H").EntireColumn.Hidden = True
End If
End Sub
End Sub
-
Apr 28th, 2013, 10:21 PM
#4
Hyperactive Member
Re: Run Macro on multiple worksheets within an excel file
Your first End Sub should be a next statement
-
Apr 28th, 2013, 11:05 PM
#5
Re: Run Macro on multiple worksheets within an excel file
Thanks kiwi. typo fixed.
Try it now biyi11
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|