+ Reply to Thread
Results 1 to 5 of 5

Use VLOOKUP in VBA to set ActiveCell

  1. #1
    Forum Contributor
    Join Date
    06-08-2012
    Location
    Panama City, FL
    MS-Off Ver
    Excel 2016
    Posts
    175

    Use VLOOKUP in VBA to set ActiveCell

    Hello Excel friends,

    Your excellent assistance is greatly appreciated.

    I am training myself to use VBA and I am stumped. I created a sample table using A1:A5 for sorted names and B1:B5 for a grade (0-100). I am currently learning about ActiveCell and Offset. Rather than clicking on a cell and that being my ActiveCell, in my macro I would like to use VLOOKUP("Steven",A1:B5,2,False) to select the cell that should become the ActiveCell. In this case "Steven" is A4, therefore my ActiveCell should be B4.

    I tried ActiveCell = VLOOKUP("Steven",A1:B5,2,False) and get a compile error: Sub or Function not defined.

    Any ideas out there?

    Thanks!

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Use VLOOKUP in VBA to set ActiveCell

    You can't really use VLOOKUP for that because it returns a value not a row/cell.

    However instead of VLOOKUP you could use MATCH.

    Also, if you want to use worksheet functions in code you need to use Application.WorksheetFunction (or, as I have in the following code, just Application).
    Please Login or Register  to view this content.
    Last edited by Norie; 03-07-2015 at 04:32 PM.
    If posting code please use code tags, see here.

  3. #3
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: Use VLOOKUP in VBA to set ActiveCell

    You can also use .Find, like below. As an aside, you can almost always avoid using ActiveCell. You can instead just refer to the found cell directly w/o needing to activate it.

    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    06-08-2012
    Location
    Panama City, FL
    MS-Off Ver
    Excel 2016
    Posts
    175

    Re: Use VLOOKUP in VBA to set ActiveCell

    [SOLVED]

    Thank you very much for the immediate and perfect response. That's why I call you folks my excellent friends.
    I can appreciate that you 'put me to the test' of analyzing a problem by leaving out the closing " in the A1:A5 range to
    make me think about it rather than just copy and enjoy. It improves the learning process.

    I'm sure this will help others new learners along the way.

    Have a great day!

  5. #5
    Forum Contributor
    Join Date
    06-08-2012
    Location
    Panama City, FL
    MS-Off Ver
    Excel 2016
    Posts
    175

    Smile Re: Use VLOOKUP in VBA to set ActiveCell

    [SOLVED]
    ...and this too is another Great Reply. It really helps to learn more than one way to do it.
    I think it would otherwise have been a long way in the learning process before I would ever come across "If Not c Is Nothing". Pretty impressive. Thanks!

+ 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. Copying an activecell range and pasting to another activecell range
    By Londonbound in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-12-2014, 07:41 AM
  2. [SOLVED] copy rows with activecell value and insert rows after activecell
    By a.hudrea in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-21-2014, 09:05 AM
  3. Selecting Activecell and cell next to the Activecell
    By Raghukumarn in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-31-2013, 06:32 AM
  4. Output contents of Activecell when Activecell may be string or numeric.
    By jfriddle in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-09-2012, 12:27 PM
  5. [SOLVED] activecell & Vlookup
    By flow23 in forum Excel General
    Replies: 1
    Last Post: 12-22-2005, 11:23 AM

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