Select Sheet Paste on last

ArturS75

New Member
Joined
Apr 29, 2024
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hi,

I got this code

LastSheet = Sheets.Count
Sheets("Template").Copy After:=Sheets(LastSheet)

Copies All template sheet and creates sheet and paste the content.

I cannot work out how to do the same but copy only a range of cells in Template?
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Welcome to the Board!

Something like this:
VBA Code:
'   Insert new sheet at end
    Dim sht As Worksheet
    Set sht = Sheets.Add(After:=Sheets(Sheets.Count))
    
'   Copy range from range A1:B2 of "Template" sheet to cell A1 of new sheet
    Sheets("Template").Range("A1:B2").Copy sht.Range("A1")
 
Upvote 0
Hello,

That did the trick. Thank you.
The previous code (the first one) Added a count to the new created sheet.
So it would be Template1, Template 2, Template 3, etc.

So, what I want to do is
copy range of cells from "Template"
Paste that range into new sheet which creates and adds a count Template1 then Template 2. Is Template 2 created then it creates Template3. :)
 
Upvote 0
You could do this:
VBA Code:
'   Insert new sheet at end
    Dim sht As Worksheet
    Set sht = Sheets.Add(After:=Sheets(Sheets.Count))
    sht.Name = "Template" & Sheets.Count + 1
    
'   Copy range from range A1:B2 of "Template" sheet to cell A1 of new sheet
    Sheets("Template").Range("A1:B2").Copy sht.Range("A1")
 
Upvote 0
Solution
Hello,

Thanks, I think that do the trick. I just complecate things too much with my code. I just dont get it why the count starts at 4 :)
Template and then it creates Template4 :)
 
Upvote 0
Hello,

Thanks, I think that do the trick. I just complecate things too much with my code. I just dont get it why the count starts at 4 :)
Template and then it creates Template4 :)
Because it is the 4th sheet in your work book.
"Sheets.Count" does not just count the number of sheets named "Template", it counts the total number of sheets in the workbook.
If you always have 2 sheets in your workbook not named "Template...", you can just change this line:
VBA Code:
    sht.Name = "Template" & Sheets.Count + 1
to this:
VBA Code:
    sht.Name = "Template" & Sheets.Count - 1
to adjust your count down 2.
 
Upvote 0

Forum statistics

Threads
1,216,086
Messages
6,128,736
Members
449,466
Latest member
Peter Juhnke

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