Help needed modifying worksheet change vba copy/paste code

rexel12

Board Regular
Joined
Feb 19, 2002
Messages
86
Hi,

I have a spreadsheet with a number of worksheets. I have modified some of FireFytrs code to do the following (see below): In sheet 1 if the user keys X in a cell in column D, then the three cells to the left are automatically copied to sheet 2 to the next free cell in column A. This works fine.

What I need to do is if X is keyed into column E then automatically copy three cells to the left to sheet 3 to the next free cell in column A. I need to repeat this upto column G.

Any help greatly appreciated.


Private Sub Worksheet_Change(ByVal Target As Range)

Dim rng As Range
If Target.Count > 1 Then Exit Sub
Set rng = Range("D:D")
If Intersect(Target, rng) Is Nothing Then Exit Sub
Range(Target, Target.Offset(0, -3)).Copy _
Destination:=Sheets("Sheet2").Range("A65536").End(xlUp).Offset(1)


End Sub
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

phantom1975

MrExcel MVP
Joined
Jun 3, 2002
Messages
3,962
Re: Help needed modifying worksheet change vba copy/paste co

You could try this:

Private Sub Worksheet_Change(ByVal Target As Range)

Dim rng As Range
If Target.Count > 1 Then Exit Sub
Set rng = Range("D:D")
If Intersect(Target, rng) Is Nothing Goto ESpot
Range(Target, Target.Offset(0, -3)).Copy _
Destination:=Sheets("Sheet2").Range("A65536").End(xlUp).Offset(1)
ESpot:
If Target.Count > 1 Then Exit Sub
Set rng = Range("E:E")
If Intersect(Target, rng) Is Nothing Then Goto FSpot
Range(Target, Target.Offset(0, -3)).Copy _
Destination:=Sheets("Sheet3").Range("A65536").End(xlUp).Offset(1)
FSpot:
If Target.Count > 1 Then Exit Sub
Set rng = Range("F:F")
If Intersect(Target, rng) Is Nothing Then Goto GSpot 'My little joke here
Range(Target, Target.Offset(0, -3)).Copy _
Destination:=Sheets("Sheet4").Range("A65536").End(xlUp).Offset(1)
GSpot:
If Target.Count > 1 Then Exit Sub
Set rng = Range("G:G")
If Intersect(Target, rng) Is Nothing Then Exit Sub
Range(Target, Target.Offset(0, -3)).Copy _
Destination:=Sheets("Sheet5").Range("A65536").End(xlUp).Offset(1)

End Sub
 

rexel12

Board Regular
Joined
Feb 19, 2002
Messages
86
Re: Help needed modifying worksheet change vba copy/paste co

Phantom1975, that works perfectly cheers!
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,168,040
Messages
5,856,987
Members
431,844
Latest member
JasonNH

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
Top