Consulting

Results 1 to 15 of 15

Thread: Copy Paste

  1. #1

    Copy Paste

    Can anyone tell me how to write a VBA code to run an IF statement that says IF sheet1!A1 and A2 and A3 match Sheet2!A1, A2, and A3 the cut and paste Sheet2!A4 into sheet1!a4. If that makes since to anyone.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Set sh = Worksheets("Sheet2")

    With Worksheets("Sheet1")

    If .Range("A1").Value = sh.Range("A1").Value And _
    .Range("A2").Value = sh.Range("A2").Value And _
    .Range("A3").Value = sh.Range("A3").Value Then

    .Range("A4").Copy sh.Range("A4")
    End If
    End With
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Mentor MaximS's Avatar
    Joined
    Sep 2008
    Location
    Stoke-On-Trent
    Posts
    360
    Location
    you can use folowing code:

    [VBA]Sub CopyPaste()
    For i = 1 To 3
    If Sheets("Sheet1").Cells(i, 1).Value = Sheets("Sheet2").Cells(i, 1).Value Then
    Else
    Exit Sub
    End If
    Next i
    Sheets("Sheet2").Range("A4").Cut
    Sheets("Sheet1").Range("A4").Insert
    End Sub[/VBA]

  4. #4
    Did not recognize the date to match. Any other ideas.

  5. #5
    I have this VLOOKUP in Row H === =IF(IF(ISERROR(VLOOKUP(A1912,Data_2!$B$1:$L$57570,9,FALSE)),"None",VLOOKUP( A1912,Data_2!$B$1:$L$57570,9,FALSE))=0,"None",IF(ISERROR(VLOOKUP(A1912,Data _2!$B$1:$L$57570,9,FALSE)),"None",VLOOKUP(A1912,Data_2!$B$1:$L$57570,9,FALS E))). I just want to atleast put it in VBA but paste it in H.

  6. #6
    VBAX Mentor MaximS's Avatar
    Joined
    Sep 2008
    Location
    Stoke-On-Trent
    Posts
    360
    Location
    Did not recognize the date to match. Any other ideas.
    what do you mean by that??

  7. #7
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I am not sure what you are asking, but can't you simplify that formula to

    =IF(ISERROR(VLOOKUP(A1912,Data_2!$B$1:$L$57570,9,FALSE)),"None",
    IF(VLOOKUP(A1912,Data_2!$B$1:$L$57570,9,FALSE)=0,"None",VLOOKUP(A1912,Data_ 2!$B$1:$L$57570,9,FALSE)))
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  8. #8
    It would not return a copy paste. The dates are exactly the same.

  9. #9
    VBAX Mentor MaximS's Avatar
    Joined
    Sep 2008
    Location
    Stoke-On-Trent
    Posts
    360
    Location
    Isn't that what you wanted??

    Compare A1 A2 A3 from Sheet 1 with A1 A2 A3 from Sheet 2.
    If they are the same cut A4 from Sheet 2 to Sheet 1 but
    if not don't do anything.

  10. #10
    MaximS is 100% correct. But in a macro or VBA form. I can record a macro to copy paste but I can not get the long VLOOKUP to work with it. That is what I am looking to do.

  11. #11
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Would you like to restate your problem again, from the start, completely, accurately, and in detail, as we have answered the question that you asked, and now you have introduced a new factor whilst that the solution ... did not match.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  12. #12
    VBAX Mentor MaximS's Avatar
    Joined
    Sep 2008
    Location
    Stoke-On-Trent
    Posts
    360
    Location
    Sample file should give us more information.

  13. #13
    What I need is to take the data from Data_1 page and seperate on the first three pages.
    Date IS shows only the date issued. Date PD only shows those with date paid. And Date STP shows only those from
    Date stop. Only when that is complete I want to take the data_1 and erase it. Then take Data_2 and match date, check #,
    and amount with a vlookup. If matches and pastes the address from ADRess from DATA_2 onto the first three sheets. and
    delete the information. Then when I go to add my next check book information in there it pastes the new stuff
    from DATA_1 below the previous. Can any one help on this. It is to help balance my bills. Rows on all 5 tabs is A-H 1-60000. I have this VLOOKUP in Row H === =IF(IF(ISERROR(VLOOKUP(A1912,Data_2!$B$1:$L$57570,9,FALSE)),"None",VLOOKUP( A1912,Data_2!$B$1:$L$5757 0,9,FALSE))=0,"None",IF(ISERROR(VLOOKUP(A1912,Data_2!$B$1:$L$57570,9,FALSE) ),"None",VLOOKUP(A1912,Data_2!$B$1:$L$57570,9,FALSE))). I want it in VBA code. And I can not attach the excel file here.

  14. #14
    Here is the file

  15. #15
    VBAX Mentor MaximS's Avatar
    Joined
    Sep 2008
    Location
    Stoke-On-Trent
    Posts
    360
    Location
    try this attachment I hope it's exactly what you want.

Posting Permissions

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