+ Reply to Thread
Results 1 to 7 of 7

Thread: VBA help with Vlookup

  1. #1
    Registered User
    Join Date
    03-06-2011
    Location
    San Jose, USA
    MS-Off Ver
    Excel 2007
    Posts
    3

    Unhappy VBA help with Vlookup

    Hello folks,
    I am a novice with VBA programming in Excel.

    I am trying to do a simple VLOOKUP of Sheet1, Column B Values in Sheet2,Column1
    As you can see from attachment VLOOKUP function in Excel but I am unable to get this simple thing done using a macro.

    Please advise/help.

    Thanks,
    Gaurav
    Attached Files Attached Files

  2. #2
    Forum Guru TMShucks's Avatar
    Join Date
    07-15-2010
    Location
    Manchester, England
    MS-Off Ver
    MSO 2003 & 2007
    Posts
    6,230

    Re: VBA help with Vlookup

    Not sure I understand what you want to do with a macro but:

        Range("C2").FormulaR1C1 = "=VLOOKUP(RC[-1],Sheet2!R1C1:R6C1,1,FALSE)"

    Or:

        Range("C2:C11").FormulaR1C1 = "=VLOOKUP(RC[-1],Sheet2!R1C1:R6C1,1,FALSE)"

    Regards

  3. #3
    Registered User
    Join Date
    03-06-2011
    Location
    San Jose, USA
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: VBA help with Vlookup

    Thanks !
    I have recorded a similar macro but the problem comes when my column positions are not fixed.

    It would be really helpful, if some code snippet can be shared which does not use R1C1 format.

    -Gaurav

  4. #4
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,640

    Re: VBA help with Vlookup

    Why do you need VBA to add the formula?
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

  5. #5
    Valued Forum Contributor
    Join Date
    06-19-2010
    Location
    Holywell, N Wales, UK
    MS-Off Ver
    Excel 2007
    Posts
    351

    Re: VBA help with Vlookup

    Hi sgaurav
    Welcome to the forum
    As Roy says it may be a sledgehammer to crack a nut but .. you're the customer!

    I have attached a probably lengthy solution (loop within a loop) but if it gives you ideas and takes you forward with your VBA coding then its worth it.
    Roy and others can make this more efficient and more elegant.
    barry
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    03-06-2011
    Location
    San Jose, USA
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: VBA help with Vlookup

    Barry - Thanks !
    This helps.

    Roy,
    I have to perform some repititive data analysis. The task and data format is fixed but not the data.
    Hence I tried by creating a simple dummy excel to see how VLookup query will be coded in macro which I can finally extend to real data.

    Thanks,
    Gaurav

  7. #7
    Registered User
    Join Date
    03-18-2011
    Location
    Ohio, USA
    MS-Off Ver
    Excel 2010
    Posts
    1

    Re: VBA help with Vlookup

    Quote Originally Posted by barryleajo View Post
    Hi sgaurav
    Welcome to the forum
    As Roy says it may be a sledgehammer to crack a nut but .. you're the customer!

    I have attached a probably lengthy solution (loop within a loop) but if it gives you ideas and takes you forward with your VBA coding then its worth it.
    Roy and others can make this more efficient and more elegant.
    barry
    This is very similar to what I was looking for. But how would the code change to reference the look up table being in a seperate workbook? Can the workbook remain closed? Thanks.
    Last edited by icon123; 03-18-2011 at 04:27 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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.2.0