Copy cells if condition is met

Quasar Hunter

New Member
Joined
Oct 23, 2020
Messages
4
Office Version
  1. 2016
Platform
  1. Windows
Hi everyone,

I have 3 tables on the same sheet Table 1 (A4:E23), Table 2 (J5:M19) and Table 3 (J21:M35).
I want to copy data from Table 1 in columns B,C,D,E to first empty row in
table 2 if the value in column A is "TK2", and copy to table 3 if value is "TK3".

Thanks!
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
If your tables have headers then Try this:
VBA Code:
Sub CopyBetweenTables()
Dim Lr1 As Long, Lr2 As Long

For i = 4 To 23
Lr1 = Range("J19").End(xlUp).Row + 1
Lr2 = Range("J35").End(xlUp).Row + 1
If Cells(i, 1).Value = "TK2" Then
Range("J" & Lr1 & ":M" & Lr1).Value = Range("B" & i & ":E" & i).Value
ElseIf Cells(i, 1).Value = "TK3" Then
Range("J" & Lr2 & ":M" & Lr2).Value = Range("B" & i & ":E" & i).Value
End If
Next i
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,212,933
Messages
6,110,752
Members
448,295
Latest member
Uzair Tahir Khan

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