How to specify the column range to be copied when moving data between sheets?

AshleyB00

New Member
Joined
Feb 9, 2023
Messages
2
Office Version
  1. 2019
Platform
  1. Windows
Currently, I have Table 1 on Sheet 1, that uses Columns A to I, and another table a few columns over that are unrelated. I'm trying to copy a row from Table 1 to Sheet 2 when certain criteria is met, but only including columns A-I of Table 1. My current code successfully copies the row from Sheet 1 to Sheet 2, but includes all columns past Table 1. The code is also made to clear the contents from Sheet 1 after copied.
How do I add limit the range of columns to be copied, so it doesn't other affect tables in the same rows? I'm very new to this so please and thank you!

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim r As Long
Dim Lastrow As Long

If Target.Column = 9 Then
Application.EnableEvents = False

r = Target.Row
Lastrow = Sheets("Completed").Cells(Rows.Count, "I").End(xlUp).Row + 1

If Target.Value = "Done" Then
    Rows(r).Copy Sheets("Completed").Cells(Lastrow, 1)
    Rows(r).ClearContents
End If

End If
Application.EnableEvents = True


End Sub
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Hi AshleyB00,

what about

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim r As Long
Dim Lastrow As Long

If Target.Column = 9 Then
  Application.EnableEvents = False
  
  r = Target.Row
  Lastrow = Sheets("Completed").Cells(Rows.Count, "I").End(xlUp).Row + 1
  
  If Target.Value = "Done" Then
    With Range("A" & r).Resize(1, 9)
      .Copy Sheets("Completed").Cells(Lastrow, 1)
      .ClearContents
    End With
  End If

End If
Application.EnableEvents = True

End Sub

Ciao,
Holger
 
Upvote 0
Solution
Hi AshleyB00,

what about

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim r As Long
Dim Lastrow As Long

If Target.Column = 9 Then
  Application.EnableEvents = False
 
  r = Target.Row
  Lastrow = Sheets("Completed").Cells(Rows.Count, "I").End(xlUp).Row + 1
 
  If Target.Value = "Done" Then
    With Range("A" & r).Resize(1, 9)
      .Copy Sheets("Completed").Cells(Lastrow, 1)
      .ClearContents
    End With
  End If

End If
Application.EnableEvents = True

End Sub

Ciao,
Holger
Amazing! It works perfectly. Thanks so much Holger!
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,583
Members
449,089
Latest member
Motoracer88

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