+ Reply to Thread
Results 1 to 6 of 6

Macro to enter person's name in one column if another column is equal to X

  1. #1
    Registered User
    Join Date
    10-23-2012
    Location
    Oxfordshire, England
    MS-Off Ver
    Excel 2010
    Posts
    3

    Macro to enter person's name in one column if another column is equal to X

    Hi,

    We have different sales reps who deal with different areas of the UK, companies are allocated to sales reps depending on the start of the company's postcode. E.g. postcode starting AB is allocated to Joe Bloggs, postcode starting NE is allocated to Fred Smith.

    I have an Excel spreadsheet containing companies from all over the UK (postcode in column P) and I need the corresponding sales rep's name entered into column D.

    The postcodes are in full, so it would read, for example, AB21 3GY rather than just AB, so the macro would need to look at the start of the cell, which could be either two letters or one, as some postcodes have just one letter at the start.

    I did try an IF formula rather than a macro, but I think it will get too complicated (or be impossible) as there are many postcodes.

    Is anyone able to help?

    Many thanks

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Macro to enter person's name in one column if another column is equal to X

    Try this, you will need to edit to match all your sales reps. You could also probably do better using lookup but it would be easier to create with a copy of your workbook;

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    10-23-2012
    Location
    Oxfordshire, England
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Macro to enter person's name in one column if another column is equal to X

    Thanks stnkynts, that's a great help! Just one question: how do I deal with postcodes that only start with one letter rather than two?

    Do I need to change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    ?

    And would that need to be a new section of the macro? (Sorry, novice!)

    *edit:

    Also, am I able to allocate more than one postcode to the same sales rep in the same line of code or do I need to do a separate section for every postcode? E.g.
    Please Login or Register  to view this content.
    Or does it need to be
    Please Login or Register  to view this content.
    etc?
    Last edited by kwilsdon; 10-24-2012 at 05:58 AM. Reason: additional query

  4. #4
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Macro to enter person's name in one column if another column is equal to X

    To answer your first question. Yes, change the 2 to a 1.

    To answer your second question:

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    10-23-2012
    Location
    Oxfordshire, England
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Macro to enter person's name in one column if another column is equal to X

    Thanks again stnkynts, very helpful

  6. #6
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: Macro to enter person's name in one column if another column is equal to X

    @ kwilsdon

    Welcome to the forum.

    Based on your last post it seems that you are satisfied with the solution(s) you've received but you haven't marked your thread as SOLVED. I'll do that for you now but please keep in mind for your future threads that Rule #9 requires you to do that yourself. If your problem has not been solved you can use Thread Tools (located above your first post) and choose "Mark this thread as unsolved".
    Thanks.

    Also, as a new member of the forum, you may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.

+ 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