+ Reply to Thread
Results 1 to 8 of 8

VBA use Application.VLookup and Application.HLookup together

  1. #1
    Registered User
    Join Date
    10-14-2021
    Location
    Cardiff
    MS-Off Ver
    2016
    Posts
    4

    VBA use Application.VLookup and Application.HLookup together

    Hi everyone,

    I have a table with multiple numbers on the left-hand side column and String value on the first row as headers.

    I get one number from a different spreadsheet and then I match that with the numbers on the left-hand side using vlookup. Then I need to use some matching function (such as HLookup) to find the column with the right header from which to pick the right output for the vlookup. At the moment the code looks like this:

    Please Login or Register  to view this content.
    For some reason, the code is not outputting anything, nor is it crashing. Any ideas? thanks
    Last edited by alansidman; 11-02-2021 at 03:28 AM.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: VBA use Application.VLookup and Application.HLookup together

    What are the values of all of your variables when this line executes? i, Col1, Plan, List, col2, Plan_1, Plan_2, value

    The most helpful thing would be to attach your file. See yellow banner at the top of the page.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    10-14-2021
    Location
    Cardiff
    MS-Off Ver
    2016
    Posts
    4

    Re: VBA use Application.VLookup and Application.HLookup together

    Unfortunately I cannot attach the file due to security reasons. The "i" comes from the fact that the said code runs over multiple values that must be taken from the other sheet (i.e. multiple numbers must be checked across the left hand column).

    List - The sheet from which I take the numbers which must be checked
    Col1 - some serial numbers that must be checked (from the List)

    Plan - the main worksheet in which I must match the required serial number (during each iteration)
    Plan_1 and Plan_2 values are just some numbers which define the range in which I can check within the serial number and the header called "CLOSE"

    The reason I need this is because the Plan sheet changes its headers quite often, hence I cannot Vlookup against one fixed coloumn but rather I need to Hlookup the header first and make sure I check against the right column.

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: VBA use Application.VLookup and Application.HLookup together

    I wasn't asking for definitions, although that is helpful. I am looking for examples of their actual values when this occurs.

    I appreciate the sensitivity of your data, although when calling worksheet functions from code it happens very often that the issue is in the data, not the code.

  5. #5
    Registered User
    Join Date
    10-14-2021
    Location
    Cardiff
    MS-Off Ver
    2016
    Posts
    4

    Re: VBA use Application.VLookup and Application.HLookup together

    I am afraid this is a dead end as the data is very sensitive. What if I tried replicating it in such fashion that it won't do any harm? Would that help at all? In the meantime, if any ideas come to you as to why the code wouldn't work let me know. Appreciate your help!!

  6. #6
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,466

    Re: VBA use Application.VLookup and Application.HLookup together

    Using fake data, or simply deleting all sensitive data would help.
    By your words, it seems using INDEX(MATCH,MATCH..) would do the trick.
    Quang PT

  7. #7
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,466

    Re: VBA use Application.VLookup and Application.HLookup together

    Application.VLookup(Worksheets(List).Cells(i, col2).Value, Worksheets(Plan).Range(Plan_1 & "2:" & Plan_2 & "200"), value, False)

    in which, value is in column count position. What is it?

    You can test by set any Cell = Vlookup, then run the code to see if it works.

  8. #8
    Registered User
    Join Date
    10-14-2021
    Location
    Cardiff
    MS-Off Ver
    2016
    Posts
    4

    Re: VBA use Application.VLookup and Application.HLookup together

    I will try to replicate the data and also use the INDEX(MATCH,MATCH). I'll let you know how that goes. 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. [SOLVED] Hiding Application or a Worksheet takes away the ability to use Application properties
    By tfurnivall in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-01-2016, 05:44 PM
  2. [SOLVED] VBA code to change the application.username and application.userinitials
    By jwlamb in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-10-2014, 11:25 PM
  3. [SOLVED] Obscure VBA error? Application.Run conflicts with Application.GetOpenFileName
    By mc84excel in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-15-2013, 08:31 PM
  4. [SOLVED] Problem with application.Hlookup
    By Brotherwarren in forum Excel General
    Replies: 6
    Last Post: 02-23-2006, 04:15 AM
  5. [SOLVED] difference application.quit & application.close
    By Pierre via OfficeKB.com in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-08-2005, 04:00 PM
  6. [SOLVED] [SOLVED] Application.GetOpenFilename vs Application.Dialogs(xlDialogsOpen)
    By Paul Martin in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-05-2005, 12:05 PM
  7. Replace application.RTD property by Application.RTDServers collect
    By John.Greenan in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-07-2005, 10:05 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