+ Reply to Thread
Results 1 to 4 of 4

VLookup in VBA to Paste Values

  1. #1
    Registered User
    Join Date
    08-31-2011
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    6

    VLookup in VBA to Paste Values

    Hi, I have a VBA problem which looks like it could be solved using a VLookup function but I can't seem to get the coding to work.

    Suppose I have a list of colours on Sheet 1. I have a drop-down list of this data in another sheet (Sheet 2). I then have a button for a macro which runs a process to return some information on the chosen colour. I want to copy this data and paste it in Sheet 1 on the row with the chosen colour on.

    Intuitively, I thought perhaps running a VLookup might work by using the drop-down list as the lookup value and the data set on Sheet 1 as the table array then offsetting the selection by one to the right before pasting. Alternatively, I've tried using the data-set and adjacent column as the table array and selecting the cell in row 2. Neither's worked which may be due to my coding being terrible or me approaching the problem in a silly way.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: VLookup in VBA to Paste Values

    Assuming Sheet1 colors in column A, Sheet2 has a color chosen in A2 and a value in B2 you want to "transfer" to Sheet1, then this will work:

    Please Login or Register  to view this content.

    If you want to transfer the value to the next empty cell in the same row so you never replace any values already transfered, but keep adding more and more, change this line of code:
    Please Login or Register  to view this content.

    The button that activates this macro needs to reside on Sheet2.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    08-31-2011
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: VLookup in VBA to Paste Values

    That's great, thanks!

    Is it possible to extend this and suppose my macro returned a range of data in Sheet2 in cells B2:B5, copy and paste this column as a row into Sheet1 alongside the colour?

    If not, I can always repeat your code for the other values

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: VLookup in VBA to Paste Values

    Anything is possible. Finish "designing" your sheets, then post the final layout here with all the desired goals and we can get it done in one shot.

    Click GO ADVANCED and use the paperclip icon to post up a copy of your workbook.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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