VBA code to copy data from specific columns in target row instead of entire row

handoverhammer

New Member
Joined
Mar 30, 2018
Messages
24
Hi Excel Wizards,

Right now once a drop down value is selected (ans), a time stamp is added to H and the entire row is copied to another sheet (ans) corresponding with the drop down. Here is a shorten version of what I have, with one example using the value TEST.

Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)    If Intersect(Target, Range("J:J")) Is Nothing Or Target.Cells.Count > 1 Then Exit Sub
    Application.ScreenUpdating = False
    Application.EnableEvents = False
    Dim LastRow As Long
    On Error GoTo errhandler
    Dim ans As String
    ans = Target.Value


    If ans = "TEST" Then
    Cells(Target.Row, "H").Value = Now
    Target.EntireRow.Copy Sheets(ans).Cells(Sheets(ans).Rows.Count, "A").End(xlUp).Offset(1, 0)
    End If

Sheets(ans).Select
    Target.EntireRow.Delete
    
errhandler:
    Application.EnableEvents = True
    Application.ScreenUpdating = True
End Sub

[INDENT][/INDENT]

Instead of copying data from the entire row, I would like to only copy data in that row from columns A:H.

So, what do I modify in this line of code?

Code:
Target.EntireRow.Copy Sheets(ans).Cells(Sheets(ans).Rows.Count, "A").End(xlUp).Offset(1, 0)

Thanks in advance!
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Try:

Code:
Range(Cells(Target.Row,"A"),Cells(Target.Row,"H")).Copy Sheets(ans).Cells(Sheets(ans).Rows.Count, "A").End(xlUp).Offset(1, 0)
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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