VBA code help

storer

New Member
Joined
Jul 21, 2010
Messages
15
I am looking for a few VBA codes and having used this site before I am well aware of how good you guys are.

I am using a workbook that updates on a monthly basis and it has a series of macros within it.

So, first item I need help with. Could you help me find a code that will copy my last three worksheets (regardless of their name and include the macros), and paste them within the same workbook, then I want to use the MsgBox function to change the tab names.

Any help would be greatly appreciated.
 
Here you go. Give this a try.

Code:
Sub CopySheetsAndRename()
    Dim sheetcount As Integer
    Dim sheetname As String
    sheetcount = Sheets.Count
    Sheets(sheetcount - 2).Copy After:=Sheets(Sheets.Count)
    sheetname = InputBox("Please enter the name for the first copied sheet.")
    Sheets(Sheets.Count).Name = sheetname
    Sheets(sheetcount - 1).Copy After:=Sheets(ActiveWorkbook.Sheets.Count)
    sheetname = InputBox("Please enter the name for the second copied sheet.")
    Sheets(Sheets.Count).Name = sheetname
    Sheets(sheetcount).Copy After:=Sheets(ActiveWorkbook.Sheets.Count)
    sheetname = InputBox("Please enter the name for the third copied sheet.")
    Sheets(Sheets.Count).Name = sheetname
End Sub
 
Upvote 0

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