Combine 2 Macros

hibernian3

New Member
Joined
May 2, 2019
Messages
7
Hello,

I have a workbook with 3 sheets, I am trying to copy the first 2 sheets to a new workbook without formulas. Each sheet needs a set range, which is different, can I combine these 2 Macros together?

Sub JointingTracker()
Sheets("jointing Tracker").Copy
Range("A1:P70").Copy
Range("A1").PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False

End Sub

Sub CableTracker()
Sheets("Cable Tracker").Copy
Range("A1:P46").Copy
Range("A1").PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
End Sub
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Do you mean that you'd like to copy both sheets to the same new workbook, and then convert the formulas to values? If so, try...

Code:
Sub CopyValuesToNewWorkbook()

    Sheets(Array("jointing Tracker", "Cable Tracker")).Copy
    
    With Sheets("jointing Tracker").Range("A1:P70")
        .Value = .Value
    End With
    
    With Sheets("Cable Tracker").Range("A1:P46")
        .Value = .Value
    End With
    
End Sub

Hope this helps!
 
Upvote 0
Thank you so much!! so simple once you see it..

If I wanted the new sheet be name after a cell on sheet 1 +a text input, example... New workbook name = Sheets("Cable Tracker")=G2&"inputtedtext".

Is this easy to add?
 
Upvote 0
The following macro has been amended to name the new workbook, as per your requirement, and to save the workbook in the same folder as the source workbook. Note that if a workbook with the same name already exists, it will be overwritten.

Code:
Sub CopyValuesToNewWorkbook()

    Dim strSheetName As String
    
    strSheetName = Sheets("Cable Tracker").Range("G2").Value & "inputtedtext"


    Sheets(Array("jointing Tracker", "Cable Tracker")).Copy
    
    With Sheets("jointing Tracker").Range("A1:P70")
        .Value = .Value
    End With
    
    With Sheets("Cable Tracker").Range("A1:P46")
        .Value = .Value
    End With
    
    Application.DisplayAlerts = False
    ActiveWorkbook.SaveAs Filename:=strSheetName
    Application.DisplayAlerts = True
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,592
Members
449,089
Latest member
Motoracer88

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