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

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
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,224,823
Messages
6,181,182
Members
453,021
Latest member
Mohamed Magdi Tawfiq Emam

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