How Can i get this macro to run on every tab not just the active tab?

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,187
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi everybody,
In my excel workbook i have rectangle shapes that i move around the screen using a macro to highlight an area in a chart,
its pretty basic stuff its just a rectangle shape that moves according to the commands of the macros as shown below
(this is the one to move it up a notch! )
Code:
Sub zzBlueSquaremoveup11()
ActiveSheet.Unprotect
Application.ScreenUpdating = False
ActiveSheet.Shapes.Range(Array(Range("EY3"))).Select
Selection.ShapeRange.IncrementTop -10
ActiveSheet.Protect
Application.ScreenUpdating = True
End Sub
This works perfectly,
however always looking to save time and energy i was wondering if i could improve it?
basically at the moment this works on the active workbook but every workbook is the same
so i was wondering if there would be a way to take this macro and when i run it, have it run on ever tab?

there are a few problems,
1 i don't know what the tabs will be called
2 there are 3 tabs i dont want to include called "Master" "Data" & "Charts"

so how can i get this macro to run on the selected tab then go through all the other tabs in the workbook other then the 3 i mentioned then return back to the current tab?

any ideas as i'm yet again a bit stuck!

Thanks

Tony
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
You can try using an <b>Array</b> on the worksheets. You may need to modify the code that I have for you. I have not tested it with your code added in, but you should get the idea.

Code:
Sub zzBlueSquaremoveup11()
Dim ws as Worksheet
For Each ws In ActiveWorkbook.Sheets(Array("Sheet1", "Sheet2", "Sheet3", "Sheet4"))
	With ws
		.Unprotect
			Application.ScreenUpdating = False
		.Shapes.Range(Array(Range("EY3"))).Select
			Selection.ShapeRange.IncrementTop -10
		.Protect
			Application.ScreenUpdating = True
	End With
Next ws
End Sub
 
Upvote 0
Tony,

Another option...

Code:
Sub zzBlueSquaremoveup11()
On Error Resume Next
For Each sht In ThisWorkbook.Sheets
Select Case sht.Name
Case "Master", "Data", "Charts"
Case Else
sht.Unprotect
Application.ScreenUpdating = False
sht.Shapes.Range(Array(Range("EY3"))).ShapeRange.IncrementTop -10
sht.Protect
End Select
Next sht
Application.ScreenUpdating = True
On Error GoTo 0
End Sub

Hope that helps
 
Upvote 0
This is brilliant,
thanks to both scott n phnx and snakehips for you imput, not sure which i will use going to test and play around with both see what happens,
thanks very much this is going to save me a lot of time! ;)

Thanks

Tony
 
Upvote 0

Forum statistics

Threads
1,206,830
Messages
6,075,109
Members
446,122
Latest member
sambee66

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