Macro to copy worksheet based on criteria [Closed]

Report
Posts
1
Registration date
Thursday April 24, 2014
Status
Member
Last seen
April 24, 2014
-
Posts
2675
Registration date
Sunday September 12, 2010
Status
Moderator
Last seen
November 5, 2020
-
I am fairly new to using macro's. I have 4 template worksheets and one input worksheet. Based on cell c4 in input worksheet I want to select either template 1, 2 3 or 4.

For example if Input sheet cell c4 = 1, then I want to copy and paste template one as another worksheet.

Can anyone help me with this.

Thank you!

1 reply

Posts
2675
Registration date
Sunday September 12, 2010
Status
Moderator
Last seen
November 5, 2020
448
Hi SDS007,

The following code will do as requested:
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("C4")) Is Nothing Then Exit Sub
If Target = 1 Then Sheets("1").Copy after:=Sheets(Sheets.Count)
If Target = 2 Then Sheets("2").Copy after:=Sheets(Sheets.Count)
If Target = 3 Then Sheets("3").Copy after:=Sheets(Sheets.Count)
If Target = 4 Then Sheets("4").Copy after:=Sheets(Sheets.Count)
End Sub 


Implement by right-clicking the input sheets tab and select View code. Paste code in big white field.

Best regards,
Trowa

Subscribe To Our Newsletter!

The Best of CCM in Your Inbox

Subscribe To Our Newsletter!