+ Reply to Thread
Results 1 to 10 of 10

Is it best practice to add helper columns or is there a better way to vlookup?

  1. #1
    Registered User
    Join Date
    12-06-2022
    Location
    UK
    MS-Off Ver
    2022
    Posts
    5

    Is it best practice to add helper columns or is there a better way to vlookup?

    I need to lookup pay rate exceptions from a separate sheet. On the separate sheet, I have four tables:
    1. Client names, days of the week, and job type
    2. Second table with days of the week, job type and location
    3. Third table with Days of the week and job type
    4. Fourth table for Standard rates including days of the week and job type

    How I have done this is a macro creates three new tables, creating combinations of:
    1. Combo 1: Client + Days of the week + Job Type
    2. Combo 2: Days of the week + Job Type + Location
    3. Combo 3: Days of the week + job type

    I have also added these combo columns on the separate sheet, and am using a vlookup with nested if to check in hierarchy of Table 1, then 2, then 3, and if it matches none of the exceptions then table 4 Standard rates.

    The result is a very long if statement with many vlookups.

    It works fine but I want to make sure I'm following best practices and I'm not sure if there is a better way to do this. I tried to use AND statements but it ended up looking even more complicated. So I'm just looking for advice to make sure I'm learning the right way.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,896

    Re: Is it best practice to add helper columns or is there a better way to vlookup?

    Fast answers need visual help. Please read the yellow banner at the top of this page on how to attach a file and a mocked up solution.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Registered User
    Join Date
    12-06-2022
    Location
    UK
    MS-Off Ver
    2022
    Posts
    5

    Re: Is it best practice to add helper columns or is there a better way to vlookup?

    Here is an example file.
    In my original case the Exception sheet is a separate file.
    So I would have the Main file and a macro that reads the values from the second and creates the third sheet. Here three helper columns are added and then used for vlookups.
    I'm trying to understand if this is best practice or if there is a better way to do this.
    Thanks!
    Attached Files Attached Files

  4. #4
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: Is it best practice to add helper columns or is there a better way to vlookup?

    Hello.
    In the 'Exceptions' sheet you have 4 tables from which -I imagine- you obtain a 'Pay' value and put that value in column G of the 'Main file' sheet.

    To help you, you must explain when one table or another is used within those 4 mentioned tables.

    Attached cleaner workbook.
    Attached Files Attached Files
    You are always very welcome if you add reputation by clicking the * (bottom left) of each message that has helped you.

  5. #5
    Registered User
    Join Date
    12-06-2022
    Location
    UK
    MS-Off Ver
    2022
    Posts
    5

    Re: Is it best practice to add helper columns or is there a better way to vlookup?

    Hi apologies for not adding more detail,
    So, the hierarchy goes, it first sees if any of the client exception applies to the invoices, in case none of those special rates apply then it checks if any location exception applies as there are certain locations that pay differently for different roles based on the day, it then checks for any role exceptions as certain roles are paid differently, neither location or role depends on the client for the time being, and finally if none of those apply, it looks at the standard rates and applies those. I would consider combining all four tables into one, but then it might be difficult for the non-technical folks updating the pay rates to keep track of how to plug in the values.

  6. #6
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: Is it best practice to add helper columns or is there a better way to vlookup?

    Ok: Let's get started on this!

    - On the 'Exceptions' sheet are the 4 tables. Later we will look for this data in the second workbook.
    Now what matters is that -it seems to me- that your tables are incomplete.

    - In the 'Main File' sheet you will see that I removed one of the helper columns and changed the formula in column C.

    - You can 'Click' the red button and analyze the results: when none of the 4 keys are found, the cell remains empty.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    12-06-2022
    Location
    UK
    MS-Off Ver
    2022
    Posts
    5

    Re: Is it best practice to add helper columns or is there a better way to vlookup?

    I went through your Macro and I'm new to this so I apologize it was a bit complex for me understand. The tables aren't incomplete, as if it meets none of the rates, there is a standard rate of 10 set. Attaching a file to show you how my macro looks, it is a bit basic as I am still learning.

    The Final Sheet that exists, my plan was to just have it and save it as a separate file so that the helper columns don't affect it.
    Attached Files Attached Files

  8. #8
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: Is it best practice to add helper columns or is there a better way to vlookup?

    Frankly, I don't understand why you re-upload your workbook to the Forum when -it's visible- all but one of its results are wrong.

    For my part, I show you the latest version of the development adding what you had omitted to mention: the value 10 for the cases that are not included in any of the 4 tables.

    To do this, I added a new and small table in which you can write the corresponding value (for example: 10).

    And please understand: there is no point in creating all those helper columns. They are not needed!
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    12-06-2022
    Location
    UK
    MS-Off Ver
    2022
    Posts
    5

    Re: Is it best practice to add helper columns or is there a better way to vlookup?

    Hi,
    Sorry I uploaded the second copy with a macro so you could see the logic I was working with. As you can see from the Macro code, I'm new to this and am having a hard time understanding your macro so I can finetune it to my need. If possible could you maybe add a couple of comments to direct which part of your macro is doing what so I can follow along.
    Thank you.

  10. #10
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: Is it best practice to add helper columns or is there a better way to vlookup?

    Attached comments:

    PHP Code: 
    Sub Macro8()
    Dim DaQ&, i&, iKeyj%
    Application.ScreenUpdating False
    Set D 
    CreateObject("Scripting.Dictionary")
    Rem -------------------\
    Rem The lookup keys from tables 1 and 2 are added to the dictionary:
    For 
    1 To 2
      a 
    Sheets("Exceptions").ListObjects(j).DataBodyRangeUBound(a)
      For 
    1 To Q
        iKey 
    "|" a(i1) & "|" a(i2) & "|" a(i3)
        
    D.Add iKeya(i4)
      
    Next
    Next
    Rem 
    -------------------\
    Rem The lookup keys from tables 3 and 4 are added to the dictionary:
    For 
    3 To 4
      a 
    Sheets("Exceptions").ListObjects(j).DataBodyRangeUBound(a)
      For 
    1 To Q
        iKey 
    "|" a(i1) & "|" a(i2)
        
    D.Add iKeya(i3)
      
    Next
    Next
    Rem 
    -------------------\
    Rem The three types of keys are assembled and looked up in the dictionary:
    With Sheets("Main file").ListObjects(1).DataBodyRange
      a 
    = .CellsUBound(a): ReDim iKey(1 To 3)
      For 
    1 To Q
        a
    (i6) = Empty
        
    iKey(1) = "|" a(i1) & "|" a(i3) & "|" a(i4)
        
    iKey(2) = "|" a(i5) & "|" a(i3) & "|" a(i4)
        
    iKey(3) = "|" a(i3) & "|" a(i4)
        
    Select Case True
          
    Case D.Exists(iKey(1)): a(i6) = D(iKey(1))
          Case 
    D.Exists(iKey(2)): a(i6) = D(iKey(2))
          Case 
    D.Exists(iKey(3)): a(i6) = D(iKey(3))
        
    End Select
    Rem The 
    final value is definedthe data found in the dictionary or the standard value:
        
    a(i1) = IIf(a(i6) = Empty, Range("St_Rate"), a(i6))
      
    Next
      
    .Columns(6) = a
    End With
    MsgBox 
    "The End."
    End Sub 
    Last edited by beyond Excel; 02-16-2023 at 08:53 AM.

+ 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. Helper Column and VLOOKUP
    By VijayJangam in forum Excel Formulas & Functions
    Replies: 16
    Last Post: 11-23-2022, 09:02 AM
  2. Formatting and merging columns - best practice
    By Der_Winzerkoenig in forum Excel General
    Replies: 12
    Last Post: 09-17-2022, 02:47 PM
  3. [SOLVED] Need dynamic vlookup if possible without helper column
    By davva23 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 07-04-2017, 07:50 AM
  4. Sort by helper column even if values in helper are alike
    By NoSleepForMe in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 08-10-2016, 04:14 AM
  5. [SOLVED] Get rid of helper columns
    By YasserKhalil in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-24-2014, 05:26 PM
  6. Helper columns
    By Blake 7 in forum Excel General
    Replies: 3
    Last Post: 02-23-2011, 06:42 AM
  7. Solution/best practice for vlookup stability
    By JoshuaSQ in forum Excel General
    Replies: 4
    Last Post: 09-24-2007, 01:15 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