+ Reply to Thread
Results 1 to 20 of 20

Macro or formula to find code and print codes

  1. #1
    Forum Contributor
    Join Date
    08-12-2012
    Location
    mysore
    MS-Off Ver
    Excel 2007
    Posts
    212

    Macro or formula to find code and print codes

    H,

    I have set of names in the column and that contains Codes like ( C,P,CP,HC,RE etc). What I have to do is,I have to find a match for these codes and write or print full form of that codes in the separate columns.I have to create two extra columns Target profile and Vertical.
    You can see the comments in the workbook.
    Please help me on this.
    Target Profile
    For Example:
    C: Customer
    P: Prospects
    CP: Customer & Prospects

    Vertical
    HC=Healthcare
    RT=Retail
    CV=Cross Vertical
    SV=Cross Vertical
    PS=Public Sector
    MF=Manufacturing
    S&D = S&D


    Please suggest me with a Macro or Formula to find this code and write proper abbreviation in the next column.

    I have attached my Work book.

    Thanks!
    Attached Files Attached Files

  2. #2
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Macro or formula to find code and print codes

    It appears all of the values in column A start with the Code and then a title.

    If this is the case you can use

    =VLOOKUP(LEFT(A2,FIND("-",A2)-2),$E$1:$F$7,2,0)

    with a lookup table in E1:F7

    Example: E1 = HC and F1 = Healthcare and so on down to row 7 or however far your codes go.
    HTH
    Regards, Jeff

  3. #3
    Forum Contributor
    Join Date
    08-12-2012
    Location
    mysore
    MS-Off Ver
    Excel 2007
    Posts
    212

    Re: Macro or formula to find code and print codes

    Hi,
    No If the name like this:

    HC - C - ANCC - Demo Email Invite T2 - Maderia (AprimoID: 129809 & Task: 130406)
    It Should print Healthcare IN vertical column and Customer in Target column as you can see HC and C both are there.

    Thanks

  4. #4
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Macro or formula to find code and print codes

    Give this a try...
    Attached Files Attached Files

  5. #5
    Forum Contributor
    Join Date
    08-12-2012
    Location
    mysore
    MS-Off Ver
    Excel 2007
    Posts
    212

    Re: Macro or formula to find code and print codes

    Hi,
    It is not showing any thing for
    P - All verts- WF Matters newsletter -
    It should show Prospect instead of NA.
    And also wherever the code comes it gives full form.
    Like for Customer & Prospect it could be CP, C&P,C/P,PC....

    Thanks,

  6. #6
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Macro or formula to find code and print codes

    You are going to have to look at all the requirements and spell them out. I can't guess at everything you want returned.

    As for as the Customer & Prospect and the different codes, build those requirements into the lookup table.

    In the case of P - All verts, same thing, build this into the lookup table.

    Try to place all your requirements into the lookup table and then if there are still some outliers then let's try to fix them.

    Overall, do the formula work. My guess is yes but the error come in when the lookup table is not built to the requirements.

  7. #7
    Forum Contributor
    Join Date
    08-12-2012
    Location
    mysore
    MS-Off Ver
    Excel 2007
    Posts
    212

    Re: Macro or formula to find code and print codes

    Hi,

    I mean if the name is start with P,C,OR CP it is not working giving N/A.

    Thanks

  8. #8
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Macro or formula to find code and print codes

    Can you provide what you have tried so far? What does your lookup table consist of? Are these code part of it?

  9. #9
    Forum Contributor
    Join Date
    08-12-2012
    Location
    mysore
    MS-Off Ver
    Excel 2007
    Posts
    212

    Re: Macro or formula to find code and print codes

    Hi,

    I can see that in the file you have provided. It is showing N/A for P that even though you have included in the look-up table.

    Thanks,

  10. #10
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Macro or formula to find code and print codes

    Please take a look at the lookup tables. You need to add it to the table on the left.

  11. #11
    Forum Contributor
    Join Date
    08-12-2012
    Location
    mysore
    MS-Off Ver
    Excel 2007
    Posts
    212

    Re: Macro or formula to find code and print codes

    It is the code:
    =VLOOKUP(TRIM(LEFT(MID(A4,FIND("-",A4)+1,255),FIND("-",MID(A4,FIND("-",A4)+1,255))-1)),$H$2:$I$4,2,0)

    I am not getting whats wrong?
    Thanks

  12. #12
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Macro or formula to find code and print codes

    There are two formulas, one in column B and one in column C.

    Column B >> =VLOOKUP(LEFT(A2,FIND("-",A2)-2),$E$2:$F$7,2,0) >> Finds the first characters before the first "-" mark

    Column C >> =VLOOKUP(TRIM(LEFT(MID(A2,FIND("-",A2)+1,255),FIND("-",MID(A2,FIND("-",A2)+1,255))-1)),$H$2:$I$4,2,0) >> Finds the value between the "-" marks

    With this in column A >> HC - C&P - ANCC - Demo Email Invite T2 - Maderia (129810)

    Column B returns >> Healthcare >> because in the lookup table $E$2:$F$7 >> HC >> equals >> Healthcare

    Column C returns >> Customer & prospects because in the lookup table $H$2:$I$4 >> C&P >> eqauls >> Customer & prospects

  13. #13
    Forum Contributor
    Join Date
    08-12-2012
    Location
    mysore
    MS-Off Ver
    Excel 2007
    Posts
    212

    Re: Macro or formula to find code and print codes

    Ok Thanks.But why it is NA for P - All verts- WF Matters newsletter ?
    Thanks

  14. #14
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Macro or formula to find code and print codes

    Is P Vertical?

    Is All verts Target profile?

  15. #15
    Forum Contributor
    Join Date
    08-12-2012
    Location
    mysore
    MS-Off Ver
    Excel 2007
    Posts
    212

    Re: Macro or formula to find code and print codes

    P is target profile and All verts is nothing. We should take only codes for match.

    Thanks

  16. #16
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Macro or formula to find code and print codes

    Wrap the formula in IFERROR

    =IFERROR(VLOOKUP(TRIM(LEFT(MID(A4,FIND("-",A4)+1,255),FIND("-",MID(A4,FIND("-",A4)+1,255))-1)),$H$2:$I$4,2,0),"")

  17. #17
    Forum Contributor
    Join Date
    08-12-2012
    Location
    mysore
    MS-Off Ver
    Excel 2007
    Posts
    212

    Re: Macro or formula to find code and print codes

    Have you got the solution?

    Thanks!

  18. #18
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Macro or formula to find code and print codes

    What did post #16 do for you?

  19. #19
    Forum Contributor
    Join Date
    08-12-2012
    Location
    mysore
    MS-Off Ver
    Excel 2007
    Posts
    212

    Re: Macro or formula to find code and print codes

    It is giving out put as blank!

    Thanks

  20. #20
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Macro or formula to find code and print codes

    How about updating your sample in post #1 as to what you have now and what is in error?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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