+ Reply to Thread
Results 1 to 11 of 11

VBA Vlookup to copy and paste

  1. #1
    Registered User
    Join Date
    05-17-2017
    Location
    North Carolina
    MS-Off Ver
    2013
    Posts
    8

    VBA Vlookup to copy and paste

    Good morning. I currently have 3 sheets. Sheet3 B40 = Lookup_value. Sheet 2 F4:H34 = Table_array. 3 = Col_index_num, and 0 = Range_lookup. Sheet1 J14 = the value I want pasted. Here is my question, issue. I want the date from Sheet3 to Vlookup the correct cell from Sheet2. I then want the value from Sheet1 J14 copy and pasted into the Vlookup cell. Below is what I was working on, however, I can't seem to get it to work. Once I can make this work, I want to be able to control this with a button that will post the value, and not the formula that is in J14. I want the information to be static. Help please.

    Sub test()

    Application.WorksheetFunction.VLookup(Worksheets("Sheet3").Range("B40"), Worksheets("Sheet2").Range("F4:H34"), 3, 0) = Worksheets("Sheet1").Range("J14").Value

    End Sub

  2. #2
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: VBA Vlookup to copy and paste

    Try:
    Please Login or Register  to view this content.
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  3. #3
    Registered User
    Join Date
    05-17-2017
    Location
    North Carolina
    MS-Off Ver
    2013
    Posts
    8

    Re: VBA Vlookup to copy and paste

    Olly,

    I am getting the following error:

    Run-time error'424':
    Object Required

  4. #4
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: VBA Vlookup to copy and paste

    Quote Originally Posted by Callandor View Post
    Olly,

    I am getting the following error:

    Run-time error'424':
    Object Required
    Which suggests you haven't tweaked that code to match your worksheet codenames...

    Might be easier if you attached your workbook.

  5. #5
    Registered User
    Join Date
    05-17-2017
    Location
    North Carolina
    MS-Off Ver
    2013
    Posts
    8

    Re: VBA Vlookup to copy and paste

    Olly,

    I got it work. Thanks for that. It actually helped me in another issue I was having. The problem with that sub you wrote me is that it doesn't do what I need it to. Unfortunately, I cannot upload the workbook. I am going to try and explain it again though, so hopefully that will be enough.

    A=sheet3.Range("B40"), which is formulated as =Today()-1, or yesterday's date.
    B=sheet2.Range("F4:F34"), which has all of the days of the month.
    C=sheet1.Range("J14"). This is the cell I want to copy from.
    D=This is the cell I want to paste the information to, which is located in column D, or two columns from the day of the month.

    I want A to find the matching day in B. Once they are a match, I want to copy C into D. Since D isn't fixed, I need it to depend entirely on A, which will change as the days change.

    I understand if you cannot help due to me being unable to upload the workbook. You have my thanks either way.
    Last edited by Callandor; 05-17-2017 at 02:53 PM. Reason: Changed what D= does.

  6. #6
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: VBA Vlookup to copy and paste

    To clarify - you want to paste the value of 'C' (Sheet1.Range("J14")) into Sheet 2, Column D, in the row where the value of Sheet2 Column F matches Sheet3.Range("B40").

    If that's the requirement, then try:
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    05-17-2017
    Location
    North Carolina
    MS-Off Ver
    2013
    Posts
    8

    Re: VBA Vlookup to copy and paste

    Olly,

    The sub is working and not working. My days of the month are controlled using formulas. When I run it, it gives me a runtime "91" error. When I write out the days of the month, instead of using the formula, the sub works. Is the .find method trying to find the code instead of the value? Thanks.

  8. #8
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: VBA Vlookup to copy and paste

    This would be much easier if you were to attach a sample workbook...

  9. #9
    Registered User
    Join Date
    05-17-2017
    Location
    North Carolina
    MS-Off Ver
    2013
    Posts
    8

    Re: VBA Vlookup to copy and paste

    Hopefully this is going to post a sample workbook.
    Attached Files Attached Files

  10. #10
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: VBA Vlookup to copy and paste

    Okay, change to:
    Please Login or Register  to view this content.
    See the extra statement, highlighted in red

  11. #11
    Registered User
    Join Date
    05-17-2017
    Location
    North Carolina
    MS-Off Ver
    2013
    Posts
    8

    Re: VBA Vlookup to copy and paste

    Works great. Thanks for all of your help.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Copy & Paste + VLookup?
    By snowstorm220 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-06-2016, 02:36 AM
  2. VBA copy paste value base on 2 vlookup value
    By SKY1015 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-25-2015, 10:58 AM
  3. [SOLVED] Vlookup with copy and paste macro
    By kasperblue in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-04-2012, 05:27 PM
  4. Vlookup VBA copy and paste
    By ashleye in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-05-2011, 05:36 AM
  5. Excel 2007 : vlookup Copy & Paste
    By Alvan9 in forum Excel General
    Replies: 1
    Last Post: 08-14-2010, 01:49 PM
  6. VBA vlookup copy paste
    By Doolafs in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 05-20-2010, 12:55 PM
  7. Vlookup copy/paste
    By Nik in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-08-2006, 12:48 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1