How to copy cell value from one table to another table with Criteria

RajG

New Member
Joined
May 4, 2021
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Hi,
I am new to VBA, please help me with the below request.

I would like to Copy the data from table1 (sheet1) to table2 (sheet2) based on the criteria "Yes" automatically or some action.

The table 1 is located in Sheet 1 and table2 is located in Sheet2.

For clear understanding I have attached the screenshot as below.

1.jpg


Thanks in advance,
Raj
 

Attachments

  • 1.jpg
    1.jpg
    59.7 KB · Views: 6

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
try this

VBA Code:
sub copypaste()
Sheets("sheet1").Select  ' can change the sheet name
Dim LR As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
With ActiveSheet
    .AutoFilterMode = False
    .Range("A1:D" & LR).AutoFilter Field:=4, Criteria1:="Yes"   ' consider the column D
End With

'Sheets("sheet2").select  ' can change the sheet name
Dim LastrowC1 As Long
LastrowC1 = Sheets("sheet1").Cells(Rows.Count, "A").End(xlUp).Row
Dim LastrowC As Long
LastrowC = Sheets("sheet2").Cells(Rows.Count, "A").End(xlUp).Row + 1
Sheets("sheet1").Range("A2:D" & LastrowC1).Copy Sheets("sheet2").Cells(LastrowC, 1)
LastrowC = Sheets("sheet2").Cells(Rows.Count, "A").End(xlUp).Row + 1

End sub



[CODE=vba]
 
Upvote 0
Hi VM,

Thanks for your prompt response!

The Table 1 value is copied to the table 2 from the bottom instead of top to bottom and when copy the value from table 1 the table rest of the value is hidden. I would like to show all the value in table 1. Then "Yes" value only moves to table 2 from the top.

Thanks in advance.

Regards,
Raj/
 
Upvote 0
just add this lines before end sub

Code:
sheets ("sheet1").select
With ActiveSheet
    .AutoFilterMode = False
End With
End sub

and regarding copy Paste, it will past in sheet 2 in last blank cells in column A.
 
Upvote 0
Solution

Forum statistics

Threads
1,214,922
Messages
6,122,281
Members
449,075
Latest member
staticfluids

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