PDA

View Full Version : Copy paste values from another workbook if criteria is met



jonnyjonjon
11-13-2017, 06:01 PM
Hello all,

I am trying to come up with a program that is able copy the values in the cells of column A of workbook 1, IF the value in the cells of column J for that row is "Customer A". And afterwards, paste it into cell A2 of workbook 2.

I've came up with the following program but I've hit a roadblock.



Dim x as workbook
Dim y as workbook
Dim lastrow as integer
Dim i as integer

Set x =workbooks.open("D:\......Workbook 1")
with x.sheets("sheet 1")
lastrow = activesheet.range("A" & Rows.Count).End(xlUp).Row

For i = 2 to last row
If range("J" & i).value = "Customer A" then
'how to copy this value or select it ?
end if
next i
end with

set y = workbooks.open("D:\......Workbook 2")
with y.sheets("sheet1")
'paste the copied values in range("A2")


Thank you in advance for the help provided

mana
11-14-2017, 03:47 AM
Sub test()


With Workbooks.Open("D:\......Workbook 1").Sheets("sheet 1").Range("A1").CurrentRegion
.AutoFilter
.AutoFilter 10, "Customer A"
If .Columns(1).SpecialCells(xlCellTypeVisible).Count > 1 Then
.Offset(1).Copy Workbooks.Open("D:\......Workbook 2").Sheets("sheet1").Range("A2")
End If
.AutoFilter
End With

End Sub



マナ

MINCUS1308
11-14-2017, 08:36 AM
:bow: