Migrating 2 macros and sorting them

cadandcode

Board Regular
Joined
Jan 21, 2023
Messages
125
Office Version
  1. 2019
Platform
  1. Windows
  2. Mobile
Sorry for my poor English, it is not MIGRATE but COMBINE
First macro (thanks to @Peter_SSs and @shinigamilight) copies and renames last sheet. This is ok.

And I am trying to add this macro I edited to run after copying sheet and renaming it.
My macro edits some rows/columns that I do each day each time.
I want to combine them and use one macro instead using two different macros, time waste.
But macro 1 (copy last sheet and rename date +1) should run first, then my macro that edits copied and renamed sheet inside.

Macro 1, copy and rename

VBA Code:
Sub New_Sheet()
  Sheets(Sheets.Count).Copy After:=Sheets(Sheets.Count)
  With Sheets(Sheets.Count)
    .Name = Format(DateValue(Replace(Left(.Name, 8), ".", "/")) + 1, "dd.mm.yy")
  End With
End Sub

Macro 2, edits some rows/columns (I made it to do its job already, just need to combine)

VBA Code:
Sub Makroyeni()
'
' Makroyeni Makro
'

'
    Range("AC3:AU3").Select
    Application.CutCopyMode = False
    ActiveCell.FormulaR1C1 = "=R[1]C"
    Range("CW7").Select
    ActiveCell.FormulaR1C1 = "1/25/2023"
    Range("D13:CU13").Select
    Selection.Copy
    Range("D11:CU11").Select
    ActiveSheet.Paste
    Range("D9:CV35").Select
    Range("CV9").Activate
    Application.CutCopyMode = False
    Selection.ClearContents
    ActiveWindow.SmallScroll Down:=20
    Range("AC39:AU39").Select
    Application.CutCopyMode = False
    ActiveCell.FormulaR1C1 = "=R[1]C"
    Range("AC40:AU40").Select
    ActiveWindow.SmallScroll Down:=30
    Range("AC75:AU75").Select
    Application.CutCopyMode = False
    ActiveCell.FormulaR1C1 = "=R[1]C"
    Range("AC76:AU76").Select
    ActiveWindow.SmallScroll Down:=15
    Range("D81:CV107").Select
    Range("CV81").Activate
    Selection.ClearContents
    ActiveWindow.SmallScroll Down:=30
    Range("AC111:AU111").Select
    ActiveWindow.SmallScroll Down:=45
    Range("AJ147:AQ179").Select
    Selection.Copy
    Range("AB147:AI147").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Range("D148:S148").Select
    Application.CutCopyMode = False
    Selection.Copy
    Range("D147:S147").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    Selection.AutoFill Destination:=Range("D147:S179"), Type:=xlFillDefault
    Range("D147:S179").Select
    ActiveWindow.SmallScroll Down:=-165
    Range("R14").Select
    ActiveWindow.SmallScroll Down:=140
    Range("BA147:CW162").Select
    Range("BA162").Activate
    Selection.ClearContents
    ActiveWindow.SmallScroll Down:=-120
    Range("D45:CV71").Select
    Range("CV45").Activate
    Selection.ClearContents
    ActiveWindow.SmallScroll Down:=20
    Range("D81:CV107").Select
    Range("CV81").Activate
    Selection.ClearContents
    ActiveWindow.SmallScroll Down:=-55
    Range("D9:CV35").Select
    Range("CV9").Activate
    Selection.ClearContents
    Selection.ClearContents
    Range("I12").Select
End Sub
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Hello from Istanbul!
Two questions:
-What is the name of the source sheet?
-Are they going to be pasted to the newly created sheet?
 
Upvote 0
Hello from Istanbul!
Two questions:
-What is the name of the source sheet?
-Are they going to be pasted to the newly created sheet?
Hello from Zonguldak friend! Thank you for your greetings.
Well, I already made it working seperately, first macro copies last sheet (with data of course) and renames it by adding 1 day in sheet name as date, like 02/02/23, macro 1, 03/02/23
And I worked on my routine and macro 2 followed and saved my steps, clearing some rows, changing some rows etc. Saved and worked as well.
But at that moment, I have to run 2 different macros and I want to combine them and use 1 macro.
Copy and rename sheet (as macro 1 does) and do the things I do (as macro 2 does).
In other words, I need to put those macros in 1 macro (combine them). The content of macros do their job, so what there written is pointless.
 
Upvote 0
If two macros are going to be on the same page, then this should work:
VBA Code:
Sub New_Sheet()
  Sheets(Sheets.Count).Copy After:=Sheets(Sheets.Count)
  With Sheets(Sheets.Count)
    .Name = Format(DateValue(Replace(Left(.Name, 8), ".", "/")) + 1, "dd.mm.yy")
  End With
  Call Makroyeni
End Sub
Running only this one should be enough. This will call the second function at the end.
Please let me know if it doesn't work.
 
Upvote 0
Solution
If two macros are going to be on the same page, then this should work:
VBA Code:
Sub New_Sheet()
  Sheets(Sheets.Count).Copy After:=Sheets(Sheets.Count)
  With Sheets(Sheets.Count)
    .Name = Format(DateValue(Replace(Left(.Name, 8), ".", "/")) + 1, "dd.mm.yy")
  End With
  Call Makroyeni
End Sub
Running only this one should be enough. This will call the second function at the end.
Please let me know if it doesn't work.
Works, wonderful on awesome tier!
 
Upvote 0

Forum statistics

Threads
1,215,582
Messages
6,125,660
Members
449,247
Latest member
wingedshoes

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