Create new sheet on cell value and copy from another sheet

manmah

Board Regular
Joined
May 11, 2009
Messages
70
Hi All
I have a project where I want to create a new sheet based on the cell input. I have used the following VB:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim wsNew As Worksheet
If Target.Cells.Count > 1 Then Exit Sub

On Error Resume Next
If Not Intersect(Target, Range("N2:N1000")) Is Nothing Then
Set wsNew = Sheets(Target.Text)
If wsNew Is Nothing Then Sheets.Add().Name = Target.Text
End If



End Sub

This works great but i need it to now copy a form from another sheet and paste it into this newly created on. as follows:

Sub COPYREPORT()
'
' COPYREPORT Macro
'


'
Sheets("REPORT MASTER").Select
Cells.Select
Selection.Copy
Sheets.Add After:=Sheets(Sheets.Count) - this is the problem???
Selection.PasteSpecial Paste:=xlPasteAllUsingSourceTheme, Operation:=xlNone _
, SkipBlanks:=False, Transpose:=False
ActiveWindow.SmallScroll Down:=-3
Range("G7:J7").Select
End Sub

The problem here is i don't know what the new sheet will be called.

Any help would be much appreciated.

Thanks
Mark
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Hi All
I have a project where I want to create a new sheet based on the cell input. I have used the following VB:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim wsNew As Worksheet
If Target.Cells.Count > 1 Then Exit Sub

On Error Resume Next
If Not Intersect(Target, Range("N2:N1000")) Is Nothing Then
Set wsNew = Sheets(Target.Text)
If wsNew Is Nothing Then Sheets.Add().Name = Target.Text
End If

End Sub

This works great but i need it to now copy a form from another sheet and paste it into this newly created on. as follows:

Sub COPYREPORT()
'
' COPYREPORT Macro
'


'
Sheets("REPORT MASTER").Select
Cells.Select
Selection.Copy
Sheets.Add After:=Sheets(Sheets.Count) - this is the problem???
Selection.PasteSpecial Paste:=xlPasteAllUsingSourceTheme, Operation:=xlNone _
, SkipBlanks:=False, Transpose:=False
ActiveWindow.SmallScroll Down:=-3
Range("G7:J7").Select
End Sub

The problem here is i don't know what the new sheet will be called.

Any help would be much appreciated.

Thanks
Mark

Try "ActiveSheet"
 
Upvote 0
Try "ActiveSheet"

Ok i've tried that:

Sub COPYREPORT()
'
' COPYREPORT Macro
'
'
Sheets("REPORT MASTER").Select
Cells.Select
Selection.Copy
ActiveSheet.Select
Selection.PasteSpecial Paste:=xlPasteAllUsingSourceTheme, Operation:=xlNone _
, SkipBlanks:=False, Transpose:=False
ActiveWindow.SmallScroll Down:=-3
Range("G7:J7").Select
End Sub

but I think its treating the REPORT MASTER sheet as the active sheet. so its just pasting it straight back on top of that one?

Thanks
Mark
 
Upvote 0
Try it like this, and leave the Sheets.Add line in.
Code:
Sheets("REPORT MASTER").Select
Cells.Select
Selection.Copy
Sheets.Add After:=Sheets(Sheets.Count) - this is the problem???
ActiveSheet.PasteSpecial Paste:=xlPasteAllUsingSourceTheme, Operation:=xlNone _
, SkipBlanks:=False, Transpose:=False
ActiveWindow.SmallScroll Down:=-3
Range("G7:J7").Select
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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