Consulting

Results 1 to 3 of 3

Thread: Copy paste values from another workbook if criteria is met

  1. #1

    Copy paste values from another workbook if criteria is met

    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

  2. #2
    VBAX Expert
    Joined
    Sep 2016
    Posts
    636
    Location
    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

    マナ

  3. #3
    VBAX Tutor MINCUS1308's Avatar
    Joined
    Jun 2014
    Location
    UNDER MY DESK
    Posts
    253
    - I HAVE NO IDEA WHAT I'M DOING

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •