Combining two macros to run together.

jsharp

New Member
Joined
Dec 12, 2022
Messages
3
Office Version
  1. 2021
Platform
  1. Windows
I've got two macros i'm running and I want them to run as one. The first one creates worksheets based off of values in my "stop data" sheet. The second one fills a shape on each of those created sheets with a static map. I want them to run at the same time if possible. The second one I have to go to each sheet individually to run. If it could run right after the sheet is created that would be great.

Sub CreateSheets()
Dim LR As Long, i As Long
Application.ScreenUpdating = False
With Sheets("Stop Data")
LR = .Range("B" & Rows.Count).End(xlUp).Row
For i = 2 To LR
Sheets("Template").Copy Before:=Sheets("Template")
ActiveSheet.Name = .Range("B" & i).Value


Next i
End With
Application.ScreenUpdating = True
End Sub

Sub MapInsert()
With ActiveSheet.Shapes("Map").Fill
.Visible = msoTrue
.UserPicture (Range("M1"))
.TextureTile = msoFalse
End With
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
You can still use two separate subs, in fact, I recommend you do. But this will cause everything to run in one go. Changes to your code in red.
Rich (BB code):
Sub CreateSheets()

   Dim LR As Long, i As Long
   
   Application.ScreenUpdating = False
   
   With Sheets("Stop Data")
      LR = .Range("B" & Rows.Count).End(xlUp).Row
      For i = 2 To LR
         Sheets("Template").Copy Before:=Sheets("Template")
         ActiveSheet.Name = .Range("B" & i).Value
         MapInsert ActiveSheet
      Next i
   End With
   
   Application.ScreenUpdating = True
   
End Sub

Sub MapInsert(WS As Worksheet)
   With WS.Shapes("Map").Fill
      .Visible = msoTrue
      .UserPicture (Range("M1"))
      .TextureTile = msoFalse
   End With
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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