Macro to copy worksheet based on criteria

Closed
SDS007 Posts 1 Registration date Thursday April 24, 2014 Status Member Last seen April 24, 2014 - Apr 24, 2014 at 04:04 PM
TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 - Apr 29, 2014 at 10:51 AM
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!
Related:

1 response

TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 555
Apr 29, 2014 at 10:51 AM
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
0