+ Reply to Thread
Results 1 to 9 of 9

Formula to auto-populate cost codes

  1. #1
    Registered User
    Join Date
    02-24-2021
    Location
    Canada
    MS-Off Ver
    Microsoft 365 2008
    Posts
    4

    Formula to auto-populate cost codes

    Hi,

    I'm trying to come up with a formula in which I can auto-populate a cost code into a column by searching for keywords in another column. A separate worksheet would contain all the descriptions and cost codes as reference for the search. The problem I'm having is that the data I'm searching through will have extra words and characters which are irrelevant to me, so it's not an exact match, and some of the descriptions fall under the same cost code. I just need to keep focus on the keywords in my description. I will then need to replicate that formula on multiple worksheets in the workbook and repeat the process on thousands of workbooks. I'm going to end up writing a macro to make the process more efficient but need to start with the basics first. Any help and/or suggestions would be appreciated.

    I'll attach a sample because it's just easier to see it than for me to poorly explain it haha.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,146

    Re: Formula to auto-populate cost codes

    In B2

    =IFERROR(INDEX('Sample Cost codes'!$B$2:$B$13,MATCH(LEFT('Sample Tab'!$A2,FIND("(",'Sample Tab'!$A2)-2),'Sample Cost codes'!$A$2:$A$13,0)),"Not found")

    Copy down

  3. #3
    Forum Expert
    Join Date
    02-10-2019
    Location
    Georgia, USA
    MS-Off Ver
    Office 365
    Posts
    2,822

    Re: Formula to auto-populate cost codes

    Similarly, since you're on MS365, you could try this:

    =XLOOKUP(LEFT(A2,SEARCH(" (",A2)-1),'Sample Cost codes'!$A$2:$A$13,'Sample Cost codes'!$B$2:$B$13,"Not Found",0)

  4. #4
    Registered User
    Join Date
    02-24-2021
    Location
    Canada
    MS-Off Ver
    Microsoft 365 2008
    Posts
    4

    Re: Formula to auto-populate cost codes

    Both of those work for the most part. I'm getting "not found" in the cell with "orientation/training" even though "orientation" is listed in the cost codes tabs and the first word in that string. Any suggestions on what's happening there?

  5. #5
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,146

    Re: Formula to auto-populate cost codes

    The match is on the full string "ORIENTATION / TRAINING " which does match "Orientation".

  6. #6
    Forum Expert
    Join Date
    02-10-2019
    Location
    Georgia, USA
    MS-Off Ver
    Office 365
    Posts
    2,822

    Re: Formula to auto-populate cost codes

    This one is a little tricky because it's kind of going backwards. Since you're on MS365, try this formula in cell B2 and copy down:

    =INDEX('Sample Cost codes'!$B$2:$B$13,MATCH(A2,XLOOKUP("*"&'Sample Cost codes'!$A$2:$A$13&"*",A2,A2,,2),0))

    This will work even if the keywords are in the middle of the description. Probably not needed I'm guessing so if the Indirect labor will always start with the same words as in the Description, you could use this:

    =INDEX('Sample Cost codes'!$B$2:$B$13,MATCH(A2,XLOOKUP('Sample Cost codes'!$A$2:$A$13&"*",A2,A2,,2),0))
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    02-24-2021
    Location
    Canada
    MS-Off Ver
    Microsoft 365 2008
    Posts
    4

    Re: Formula to auto-populate cost codes

    I have a formula used to match key words in a column and based on that keyword, return a cost code. Not all descriptions will have a cost code so I'd like to return a "XXXX" or generic cost code to let me know it's a misc/unknown code. Right now it if doesn't match it returns a "0" and I can't seem to figure out how I can return "XXXX" if it's not found.

    Here is the formula I'm using:

    =XLOOKUP(TRUE, ISNUMBER(SEARCH('Cost Code Database'!$P:$P,A3)),'Cost Code Database'!$Q:$Q)

    I've tried:

    =XLOOKUP(TRUE, ISNUMBER(SEARCH('Cost Code Database'!$P:$P,A3)),'Cost Code Database'!$Q:$Q, "XXXX") for the [If_not_found] parameter and it still returns a "0" if it's not found.

    Any help would be appreciated, Thanks!

  8. #8
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,577

    Re: Formula to auto-populate cost codes

    In B2 then copy doewn.
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Pl note
    Array formula should be confirmed with Ctrl+Shift+Enter keys together.
    If answere is satisfactory press * to add reputation.

  9. #9
    Forum Expert
    Join Date
    02-10-2019
    Location
    Georgia, USA
    MS-Off Ver
    Office 365
    Posts
    2,822

    Re: Formula to auto-populate cost codes

    To answer your question in Post#7, you could try this:

    =LET(a,XLOOKUP(TRUE, ISNUMBER(SEARCH('Cost Code Database'!$P:$P,A3)),'Cost Code Database'!$Q:$Q),IF(a=0,"XXXX",a))

    (works with 365 only)

+ 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. Auto Populate Zip Codes From Address, City, and State
    By DenverGamer in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-27-2021, 08:09 PM
  2. Auto populate 35 WBS Cost Reports
    By Essonc2001 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 12-05-2018, 09:18 AM
  3. [SOLVED] how to add cost codes and add running totals to a cell
    By kwguy in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 09-29-2016, 05:36 PM
  4. Replies: 10
    Last Post: 09-09-2016, 07:09 PM
  5. Replies: 1
    Last Post: 04-15-2013, 05:16 PM
  6. Replies: 3
    Last Post: 02-28-2012, 11:54 AM
  7. Refrencing product codes to get cost value
    By kegiannone in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-07-2010, 08:12 PM

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