+ Reply to Thread
Results 1 to 19 of 19

Assign Category based on a contact's job title using Vba

  1. #1
    Registered User
    Join Date
    10-07-2020
    Location
    Sydney
    MS-Off Ver
    2016
    Posts
    12

    Lightbulb Assign Category based on a contact's job title using Vba

    Hi All,

    I have a workbook with 2 sheets. The first sheet (Sheet Name "Contacts") has the columns in the order: Company, First Name, Last Name, Job Title, Location. The second sheet (Sheet Name: Categories) has 2 columns in the order: Job Function and Keywords.

    I need to assign the Job function to Sheet 1 (Contacts) based on the first occurrence of the keywords in Job Title of Sheet 2 (Categories) using VBA.

    Here are few Examples:
    Job Title 1: IT Security and Cloud Manager -> Job Function: Security
    Job Title 2: Cloud and IT Security Manager-> Job Function: Cloud
    Job Title 3: Technology and Security Director-> Job Function: Security
    Job Title 4: Head of Application-> Job Function: DevOps
    Job Title 5: Head of Application Security-> Job Function: Security

    Job Functions List:
    Job Function Keywords
    Security Application Security
    Security IT Security
    Security CISO
    Security Cloud Security
    Security Cyber
    Security Technology Security
    Security Information Security
    DevOps Application
    DevOps DevOps
    DevOps Software
    DevOps IT Engineering
    DevOps IT Delivery
    DevOps Product
    Cloud Cloud
    Cloud IT Operations
    Cloud IT Infrastructure
    Cloud Platform


    Sample Tool V2.0.xlsm
    Attached Files Attached Files
    Last edited by divyasn31; 12-12-2023 at 07:52 PM.

  2. #2
    Banned User!
    Join Date
    05-03-2022
    Location
    HumptyDoo, Australia
    MS-Off Ver
    365
    Posts
    101

    Re: Assign Category based on a contact's job title using Vba

    Have you got a sample workbook you can upload?

  3. #3
    Registered User
    Join Date
    10-07-2020
    Location
    Sydney
    MS-Off Ver
    2016
    Posts
    12

    Re: Assign Category based on a contact's job title using Vba

    Hi, I have attached the sample data in this post

  4. #4
    Banned User!
    Join Date
    05-03-2022
    Location
    HumptyDoo, Australia
    MS-Off Ver
    365
    Posts
    101

    Re: Assign Category based on a contact's job title using Vba

    This macro should do it;
    Please Login or Register  to view this content.
    PS as you have multiple keywords for each Job Function I have treated each keyword as a single entity.
    For example if your Keyword (singular) is "Technology Security" and your job title is "Technology AND Security Director"...it won't find it.

    You could treat each word in the Keywords column as a single keyword, but that may cause you other problems. I think it would be better to be a bit more savvy with your Keyword entries.
    Last edited by GameChanger; 12-05-2023 at 09:29 PM.

  5. #5
    Registered User
    Join Date
    10-07-2020
    Location
    Sydney
    MS-Off Ver
    2016
    Posts
    12

    Re: Assign Category based on a contact's job title using Vba

    Thanks for sharing that code. I will give a try. Will it work if I add "Technology and Security" in my keywords list?

  6. #6
    Banned User!
    Join Date
    05-03-2022
    Location
    HumptyDoo, Australia
    MS-Off Ver
    365
    Posts
    101

    Re: Assign Category based on a contact's job title using Vba

    No worries and yes, that will work

  7. #7
    Registered User
    Join Date
    10-07-2020
    Location
    Sydney
    MS-Off Ver
    2016
    Posts
    12

    Re: Assign Category based on a contact's job title using Vba

    Thank you. The code worked

  8. #8
    Registered User
    Join Date
    10-07-2020
    Location
    Sydney
    MS-Off Ver
    2016
    Posts
    12

    Re: Assign Category based on a contact's job title using Vba

    Hi, in the sheet "Categories", I have a Job Function "HR" and Keyword as "EX". If job title is say, "Head of EX and Transformation", the code should assign the Job function as HR. However, the code assigns the Job Function as HR, if the job title has the word "Executive" in it.

    For example: Job Function for "Executive Director DevOps"- should be DevOps. But the code assigns HR as Job Function as the job title has EX in Executive
    Job Function for "Director EX" should be HR

    Is there a way to solve this?

  9. #9
    Banned User!
    Join Date
    05-03-2022
    Location
    HumptyDoo, Australia
    MS-Off Ver
    365
    Posts
    101

    Re: Assign Category based on a contact's job title using Vba

    Yep maybe change it to this;

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    10-07-2020
    Location
    Sydney
    MS-Off Ver
    2016
    Posts
    12

    Re: Assign Category based on a contact's job title using Vba

    Okay. How do I dd other punctuations in addition to space? Like: , / : - &
    Also, I noticed that the code runs based on the order of keywords in the sheet "Categories". Is it possible for the code to work based on the first occurrence of the keywords from the entire list of keywords in the sheet "Categories".
    For example:
    "Head of Digital and Technology Risk" should be assigned to Digital and not Cyber Leaders
    "Head of Technology Risk, Digital and Transformation" will be assigned to Cyber Leaders.

    The keywords:
    "Digital"has the Job function "Digital"
    "Technology Risk" has the job function "Cyber Leaders"
    Last edited by divyasn31; 12-12-2023 at 07:40 PM.

  11. #11
    Banned User!
    Join Date
    05-03-2022
    Location
    HumptyDoo, Australia
    MS-Off Ver
    365
    Posts
    101

    Re: Assign Category based on a contact's job title using Vba

    Have you tried it with the punctuation you are talking about?
    If you are talking about that punctuation in your Job Title, then that line will handle that case as it looks for your keyword PLUS a space on your job title.
    The means if your keyword is EX and your job title has EX/, EX!, EX@, EX% or EX& it won't match it. It will only match with EX followed by a space eg 'EX HR'

    It does not work on the order of keywords in categories, it works on the FIRST match in the job title.

    If you think it doesn't work in this way, put up an example of where you think it doesn't give the right answer and I'll have a look at it.
    Last edited by GameChanger; 12-12-2023 at 07:51 PM.

  12. #12
    Registered User
    Join Date
    10-07-2020
    Location
    Sydney
    MS-Off Ver
    2016
    Posts
    12

    Re: Assign Category based on a contact's job title using Vba

    Yes. I tried. I have attached the Sample tool I created for this and highlighted the incorrect one in red.

    Is there a way to put an array of punctuations like this:
    Const p As String = ", /&:-"

    and whenever this punctuation appears, the punctuation can be replaced by a space in the code and then execute the rest of the logic
    Last edited by divyasn31; 12-12-2023 at 08:05 PM.

  13. #13
    Banned User!
    Join Date
    05-03-2022
    Location
    HumptyDoo, Australia
    MS-Off Ver
    365
    Posts
    101

    Re: Assign Category based on a contact's job title using Vba

    So you have changed the original code in this way (and maybe elsewhere that I haven't seen);

    c1.Offset(, 1) = c2.Offset(, -2)
    c1.Offset(, 2) = c2.Offset(, -1)

    and got rid of keywords and replaced it with title?

    So you need to explain to me WHY Cyber Leaders is wrong for that Job Tile in red and what you think it should be.

  14. #14
    Registered User
    Join Date
    10-07-2020
    Location
    Sydney
    MS-Off Ver
    2016
    Posts
    12

    Re: Assign Category based on a contact's job title using Vba

    Sure. So the job title highlighted in red is "Executive Manager Digital, Technology Risk & Resilience". The first keyword is Digital (from the Categories sheet) and the second keyword is "Technology Risk". So this job title should be assigned to the job function "Digital". Hope it makes sense :-)

  15. #15
    Banned User!
    Join Date
    05-03-2022
    Location
    HumptyDoo, Australia
    MS-Off Ver
    365
    Posts
    101

    Re: Assign Category based on a contact's job title using Vba

    OK. So adding the space created this issue.

    So you DON'T want a match if the Keyword is EX and the Job Title has 'EXECUTIVE' in it,
    BUT you DO want a match if the keyword is DIGITAL and the Job Title has 'Digital,' in it.

    Is that Correct?

  16. #16
    Registered User
    Join Date
    10-07-2020
    Location
    Sydney
    MS-Off Ver
    2016
    Posts
    12

    Re: Assign Category based on a contact's job title using Vba

    Thats right.
    Is there a way to put an array of punctuations like this:
    Const p As String = ", /&:-"

    and whenever this punctuation appears, the punctuation can be replaced by a space in the code and then execute the rest of the logic

  17. #17
    Banned User!
    Join Date
    05-03-2022
    Location
    HumptyDoo, Australia
    MS-Off Ver
    365
    Posts
    101

    Re: Assign Category based on a contact's job title using Vba

    Here is a function that will raplace those characters with a space;

    Please Login or Register  to view this content.
    Then in your code;
    Please Login or Register  to view this content.

  18. #18
    Registered User
    Join Date
    10-07-2020
    Location
    Sydney
    MS-Off Ver
    2016
    Posts
    12

    Re: Assign Category based on a contact's job title using Vba

    Thank you so much. It worked

  19. #19
    Banned User!
    Join Date
    05-03-2022
    Location
    HumptyDoo, Australia
    MS-Off Ver
    365
    Posts
    101

    Re: Assign Category based on a contact's job title using Vba

    No problems. Glad you got it sorted.

+ 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] Assign rows based on category and age
    By C J W in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-20-2019, 01:37 AM
  2. Assign Category based on Name
    By karl8695 in forum Excel General
    Replies: 14
    Last Post: 02-15-2017, 06:30 PM
  3. Wants to assign specific category based on student score
    By toofani in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-20-2015, 05:59 PM
  4. [SOLVED] If Then Macro based on one column to assign category to another
    By angeleenmc in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-13-2015, 04:00 PM
  5. Assign a category to a cell based on two conditions
    By jeffepro in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-09-2015, 07:38 AM
  6. [SOLVED] How Do I Assign Attributes to Entries Based on Category?
    By kelman17 in forum Excel General
    Replies: 6
    Last Post: 06-10-2013, 09:31 PM
  7. What can i use to display a category title based on a cells value?
    By smithjon in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 04-23-2013, 07:35 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