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

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
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
 
Upvote 0
Re: Help needed modifying worksheet change vba copy/paste co

Phantom1975, that works perfectly cheers!
 
Upvote 0

Forum statistics

Threads
1,215,038
Messages
6,122,798
Members
449,095
Latest member
m_smith_solihull

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