ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   problem coping data from 1 sheet to new sheet (https://www.excelbanter.com/excel-programming/428153-problem-coping-data-1-sheet-new-sheet.html)

[email protected]

problem coping data from 1 sheet to new sheet
 
User clicks a button to add a new vehicle. This macro is suppose to
copy all of the data in sheet "Vehicle template", then create a new
sheet and paste to that sheet.Then it opens up a UserForm.
Later I want to figure out how to have it name the new sheet based on
data in one of the sheets. But 1st, I want this part to work.

It creates a new sheet ok, but it only pastes the contents of cell A1.
Can anyone see why the entire sheet does not paste to the new sheet?

Thanks
jeff

Sub NewSheet()

Sheets("Vehicle template").Select
ActiveCell.Cells.Select
Selection.Copy
Sheets.Add
ActiveSheet.Paste

UserForm1.TextBox1.SetFocus
UserForm1.Show
End Sub

slarbie

problem coping data from 1 sheet to new sheet
 
It's your line:
ActiveCell.Cells.Select

ActiveCell refers to one cell only. Better to have a named range for your
template. For this example I named the range MyTemplate. Then this would be
your code:

Sheets.add
Range("MyTemplate").copy range("a1")

" wrote:

User clicks a button to add a new vehicle. This macro is suppose to
copy all of the data in sheet "Vehicle template", then create a new
sheet and paste to that sheet.Then it opens up a UserForm.
Later I want to figure out how to have it name the new sheet based on
data in one of the sheets. But 1st, I want this part to work.

It creates a new sheet ok, but it only pastes the contents of cell A1.
Can anyone see why the entire sheet does not paste to the new sheet?

Thanks
jeff

Sub NewSheet()

Sheets("Vehicle template").Select
ActiveCell.Cells.Select
Selection.Copy
Sheets.Add
ActiveSheet.Paste

UserForm1.TextBox1.SetFocus
UserForm1.Show
End Sub



All times are GMT +1. The time now is 09:08 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com