+ Reply to Thread
Results 1 to 16 of 16

Formula or vba to assign a priceing band to UK postal code.

  1. #1
    Forum Contributor
    Join Date
    11-03-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    246

    Formula or vba to assign a priceing band to UK postal code.

    Hi, I have a sheet which contains customer names and addresses.

    I would like a formula or vba to look at column L and assign a price band based on the post code.
    Post codes are either 6 or 7 characters, 8 if the space is included as they are in my list. "AB1 2CD" or "AB12 3CD"
    The price band would only need to consider the first part of the post code, "AB1". "AB1 2" would be nice though.

    Thank you, your help is always appreciated.

  2. #2
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Formula or vba to assign a priceing band to UK postal code.

    You could use a lookup table, and either VLOOKUP or INDEX/MATCH to return a value based on a postcode text text string that included everything including one character after the space. That would give you the "AB1 2" functionality.

    If you can post a sample workbook it's easier to show you how.

    BSB

  3. #3
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Formula or vba to assign a priceing band to UK postal code.

    But to get you going and hopefully point you in the right direction, see attached for a VERY basic example of one way of doing this.


    BSB
    Attached Files Attached Files

  4. #4
    Forum Contributor
    Join Date
    11-03-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    246

    Re: Formula or vba to assign a priceing band to UK postal code.

    Please see arttached
    Attached Files Attached Files

  5. #5
    Forum Contributor
    Join Date
    11-03-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    246

    Re: Formula or vba to assign a priceing band to UK postal code.

    Thank you for the reply.

    I need to try and explain a bit better what I would like it to do.

    I will have the 3 bands A, B and C. Would it be possible to have a range of post codes assigned to each band?

  6. #6
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Formula or vba to assign a priceing band to UK postal code.

    Same approach applied to your data.
    Formula in the yellow cells. Lookup table is the green columns.

    The lookup table could be tucked away in a hidden sheet for the sake of tidiness.

    Hope that helps.

    BSB
    Attached Files Attached Files
    Last edited by BadlySpelledBuoy; 11-23-2015 at 01:46 PM. Reason: Correcting a typo

  7. #7
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Formula or vba to assign a priceing band to UK postal code.

    Quote Originally Posted by A440 View Post
    I will have the 3 bands A, B and C. Would it be possible to have a range of post codes assigned to each band?
    That all depends on how they are banded. Are there set criteria to define which falls into which?

    If not then one very long lookup table may be order of the day.

    BSB

  8. #8
    Forum Contributor
    Join Date
    11-03-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    246

    Re: Formula or vba to assign a priceing band to UK postal code.

    Thanks
    I'll sort the codes in alphabetical order and mark out which is for A B or C.

  9. #9
    Forum Contributor
    Join Date
    11-03-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    246

    Re: Formula or vba to assign a priceing band to UK postal code.

    Please see attached
    Attached Files Attached Files

  10. #10
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: Formula or vba to assign a priceing band to UK postal code.

    If you take the postcodes and use Data Text to Columns and use Fixed instead of a delimiter and place the separator close to the second element of the postcode, you will end up with a 4 character code. The last character on a lot of the codes will be a space.

    Use the LEFT function to extract the first 4 characters from the postcodes given in the addresses as the lookup key for VLOOKUP.
    Enter this in G3 and fill down:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    This is looking up the first 4 characters of the postcode in the table that is in M3:N10 as below:

    M
    N
    3
    SY1 A
    4
    SY2 A
    5
    SY7 B
    6
    SY9 B
    7
    TF1 B
    8
    TF4 B
    9
    TF9 C
    10
    WV16 C


    Here is your workbook back with the formula and the small table so that you can experiment with it.
    Attached Files Attached Files
    <---------If you like someone's answer, click the star to the left of one of their posts to give them a reputation point for that answer.
    Ron W

  11. #11
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Formula or vba to assign a priceing band to UK postal code.

    You could use the approach I showed above of using the postcode prefix and the first character of the suffix, however "SY22 6" will cause you problems as it appears under both Band A and Band B.

    As you have this list of postcodes, why not simply put them in one long list with their respective bands and use that as a lookup table on the entire postcode (prefix and suffix)?

    BSB

  12. #12
    Forum Contributor
    Join Date
    11-03-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    246

    Re: Formula or vba to assign a priceing band to UK postal code.

    Ha ha, I was just working on doing that as your notification came through. it seems to work, I have also downloaded full lists of local area postcodes to cover new customers.

    Thank you all for your help, I am happy with the solution I now have.

  13. #13
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Formula or vba to assign a priceing band to UK postal code.

    Happy to help.

    Thanks for the rep point.

    BSB

  14. #14
    Forum Contributor
    Join Date
    11-03-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    246

    Re: Formula or vba to assign a priceing band to UK postal code.

    Your welcome.

    I appear to have a problem with it now, it was working fine but it has now decided to return #REF! for all of them.
    I must of moved something in the formula.
    I'll come back to you if thats ok if I cant sort it.

  15. #15
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Formula or vba to assign a priceing band to UK postal code.

    By all means. Here to help.

    BSB

  16. #16
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: Formula or vba to assign a priceing band to UK postal code.

    Examine your references to be sure that they are actually pointing to the correct cells.

+ 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. Postal Code List
    By KhalidIraq in forum Excel General
    Replies: 4
    Last Post: 01-09-2015, 10:39 AM
  2. [SOLVED] Help with Postal Code in Userform
    By eddyrcabrera79 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-04-2013, 08:14 PM
  3. Extract Postal code
    By terrysoper1973 in forum Excel General
    Replies: 10
    Last Post: 09-18-2011, 01:10 PM
  4. Postal Code Format
    By naive_nadeem in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-07-2011, 01:44 PM
  5. Postal code formatting
    By raventroth in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-01-2010, 10:15 AM
  6. [SOLVED] Validation of Postal Code
    By Veronika in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-16-2005, 05:45 PM
  7. US county formula from Postal Code
    By manz77 in forum Excel General
    Replies: 0
    Last Post: 02-01-2005, 04:40 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