+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    Registered User
    Join Date
    12-10-2009
    Location
    london, england
    MS-Off Ver
    Excel 2000
    Posts
    13

    Smile Populate column for list of towns

    Hello Guys
    I am new and have just registered, I have been trying to solve a problem for over a week now in excel.

    I have a list of towns, region

    The list is over 1500 records for each

    I was wondering if there is a way I can fill in the region and country columns automatically -i.e. through a script or function or macro based on what is entered in the town row/ field

    e.g

    Town= Cheltenham

    if the town is Cheltenham, I would like the corresponding region column to pollute with glouctershire

    I have tried using functions such as:

    =IF(A3="CHELTENHAM","Glouctershire",IF(A3="LONDON","LONDON",IF(A3="Leeds","Yorkshire",A9)))


    but as I have over 1500 towns, the error message comes up in excel stating the formula is too long- I think it is limited to 255 characters or so

    I would appreciate any help as it is urgent.

    Thanks to all in advance[/SIZE][/SIZE]
    Last edited by kingjasonwill; 12-10-2009 at 09:52 PM. Reason: Need to change title

  2. #2
    Forum Moderator teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    2003 & 2010
    Posts
    10,042

    re: Populate column for list of towns

    Thanks for changing the title and the font.

    You'll need to set up a lookup table like this:


    Code:
    city	region
    Cheltenham	Glouctershire
    London	London
    Leeds	Yorkshire
    etc.
    If you put this table in columns x and y, starting in row 1, then you can use VLOOKUP() instead of nested IFs

    =vlookup(A3,$x$1:$y$100,2,false)

    adjust cell addresses to suit

    hth
    teylyn
    Microsoft MVP - Excel
    At Excelforum, you can say "Thank you!" by clicking the icon below the post.

    Avoid pie charts with more than two data points. Why? See here (pdf, 559 kb). The only acceptable pie chart is here.

  3. #3
    Registered User
    Join Date
    12-10-2009
    Location
    london, england
    MS-Off Ver
    Excel 2000
    Posts
    13

    re: Populate column for list of towns

    Hi

    Sorry I am new to using excel, can you please explain to me what the line:
    =vlookup(A3,$x$1:$y$100,2,false)
    means and where I change the values?

    Say Cheltenham is in A2 and I want Glouctershire is in B2

    So If I input cheltenham anywherein the A column, it will update corresponding B column with Gloucestershire

    and the same for London in A3
    Leeds in A4

    Thanks, your assistance will be appreciated

  4. #4
    Registered User
    Join Date
    12-10-2009
    Location
    Queensland, Australia
    MS-Off Ver
    Excel 2003
    Posts
    4

    re: Populate column for list of towns

    Hi kingjasonwill,

    If you have the lookup table set up as mentioned in the previous post, then you put that formula in the place you want it to show the region.

    So if A2 is Cheltenham then you put the Vlookup formula in B2. The formula then scans the list for Cheltenham, and returns the corresponding entry from column 2.

    Are the locations you need to place regions aganst unique or duplicated throughout the record sets?

  5. #5
    Registered User
    Join Date
    12-10-2009
    Location
    london, england
    MS-Off Ver
    Excel 2000
    Posts
    13

    re: Populate column for list of towns

    Hi

    thanks for the reply.

    Yes they are duplicated throughout.

    e.g. a list such as:


    london
    cheltenham
    london
    london
    cheltenham
    leeds
    leeds
    cheltenham
    glasgow
    glasgow

    I have tried the formula and it works but it brings up a #N/A message if the names are duplicated?

    Can you help or guide me as to what I am doing wrong please?

  6. #6
    Registered User
    Join Date
    12-10-2009
    Location
    Queensland, Australia
    MS-Off Ver
    Excel 2003
    Posts
    4

    re: Populate column for list of towns

    Your lookup table should include each name and area only once. Also if you are populating the formula with autofill what your range, as it will move it down automatically.

    So if your lookup table has london on top, and your initial range was A1:B2 in the formula and you autofill, range in the second formula will be A2:B3, so you need to make the range an absolute reference so that it still sees London at the top.

    Cheers,
    Justin

  7. #7
    Registered User
    Join Date
    12-10-2009
    Location
    london, england
    MS-Off Ver
    Excel 2000
    Posts
    13

    re: Populate column for list of towns

    OK, Thanks, But I am a little confused, sorry.

    I have included the file I am working on, I have simply created votes data.

    Can you please check it and see what is wrong please?
    Attached Files Attached Files

  8. #8
    Forum Moderator teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    2003 & 2010
    Posts
    10,042

    re: Populate column for list of towns

    Hi,
    You're almost there! Just one thing: you're using relative references for the lookup range, so the references will change when the formula is copied down. Instead of

    =VLOOKUP(C2,Party!A1:B10,2,FALSE)

    Use

    =VLOOKUP(C2,Party!$A$1:$B$10,2,FALSE)

    With the $sign, the cell addresses are "absolute" and won't be changed when the formula is copied down. You want the C2 to be adjusted to C3 in the next row etc, but you always want to look up the same table, so you must make sure the lookup table is referenced with absolute references.

    Hope that makes it clearer.
    teylyn
    Microsoft MVP - Excel
    At Excelforum, you can say "Thank you!" by clicking the icon below the post.

    Avoid pie charts with more than two data points. Why? See here (pdf, 559 kb). The only acceptable pie chart is here.

  9. #9
    Registered User
    Join Date
    12-10-2009
    Location
    london, england
    MS-Off Ver
    Excel 2000
    Posts
    13

    re: Populate column for list of towns

    Yes, that makes it a million times clearer, thanks million for your help

  10. #10
    Registered User
    Join Date
    12-10-2009
    Location
    london, england
    MS-Off Ver
    Excel 2000
    Posts
    13

    re: Populate column for list of towns

    Hi

    Just one more thing, I have tried the solution, I was wondering can you please tell me how to ensure if my lookup value is not in the lookup list, i.e. no corresponding region, the field doesn't display #N/A and can just be blank?

    Thanks in advance

  11. #11
    Registered User
    Join Date
    12-10-2009
    Location
    london, england
    MS-Off Ver
    Excel 2000
    Posts
    13

    re: Populate column for list of towns

    Hi

    Also

    I would like to save the excel document as a CSV file to import into SQL.
    How can I clean up the worksheet to show only the values from the formulas not the actual formula?

  12. #12
    Forums Administrator royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    24,447

    re: Populate column for list of towns

    To best describe or illustrate your problem you would be better off attaching a dummy workbook, the workbook should contain the same structure and some dummy data of the same type as the type you have in your real workbook - so, if a cell contains numbers & letters in this format abc-123 then that should be reflected in the dummy workbook.

    If needed supply a before and after sheet in the workbook so the person helping you can see what you are trying to achieve.

    Doing this will ensure you get the result you need!
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel consulting, free examples and tutorials visit Excel Consulting-Excel VBA
    Check out the free Excel Toolbar

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)


    Code Tags: Make your code easier for us to read

  13. #13
    Registered User
    Join Date
    12-10-2009
    Location
    london, england
    MS-Off Ver
    Excel 2000
    Posts
    13

    Re: Populate column for list of towns

    Hi

    Thanks

    Here is an attachment of the file I am working on

    At the moment, 78 does not match any corresponding values in the lookup table. This may be the case when I polute all data. So I would like to know how to make sure the #N/A does not show up in D7 on the "voters" worksheet.

    Also if I was to save the file as a CSV file to import into my phpmyadmin, how do I clean up table so it can show final values only in voters worksheet so I can delete the "Party Codes" worksheet.

    Many thanks well in advance

    Can you help please?
    Attached Files Attached Files

  14. #14
    Registered User
    Join Date
    12-10-2009
    Location
    london, england
    MS-Off Ver
    Excel 2000
    Posts
    13

    Re: Populate column for list of towns

    hi

    when i say I would like it to not show up the #N/A value, I mean is it possible for it to remain blank if there is no value to look up in the "Party Codes" table

    Thanks

    Can you help please?

  15. #15
    Forum Moderator teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    2003 & 2010
    Posts
    10,042

    Re: Populate column for list of towns

    Hi,

    the easiest, though not the most elegant is

    =IF(ISNA(<the vlookupformula>),"",<the vlookupformula>)
    teylyn
    Microsoft MVP - Excel
    At Excelforum, you can say "Thank you!" by clicking the icon below the post.

    Avoid pie charts with more than two data points. Why? See here (pdf, 559 kb). The only acceptable pie chart is here.

Thread Information

Users Browsing this Thread

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

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.2.0