+ Reply to Thread
Results 1 to 19 of 19

Populate column for list of towns

  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 Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    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:


    Please Login or Register  to view this content.
    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

  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 Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    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.

  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
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    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
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  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 Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: Populate column for list of towns

    Hi,

    the easiest, though not the most elegant is

    =IF(ISNA(<the vlookupformula>),"",<the vlookupformula>)

  16. #16
    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 Can you tell me where I include that line in the following:

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

    or how do I implement that line?

    =IF(ISNA(<the vlookupformula>),"",<the vlookupformula>) into my lookup line?

    Thanks
    Can you help please?

  17. #17
    Forum Expert darkyam's Avatar
    Join Date
    03-05-2008
    Location
    Houston, TX
    MS-Off Ver
    2013
    Posts
    2,191

    Re: Populate column for list of towns

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

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

    Re: Populate column for list of towns

    thanks, this works, but do you know how i can use this in multiple rows,
    I trie copying and pasting but this completely slows down excel and even freezes as there are over 45,000 records.

    Can you suggest a way to make it quicker if at all possible?

    Thanks in advance

    Can you help?

  19. #19
    Forum Expert darkyam's Avatar
    Join Date
    03-05-2008
    Location
    Houston, TX
    MS-Off Ver
    2013
    Posts
    2,191

    Re: Populate column for list of towns

    Unfortunately, no, not with a better formula I know of. (2007 has the IFERROR function, but per your profile, you're on 2000.) If you're looking up 45,000 records in 45,000 other records, you're asking Excel to do as many as 2 billion operations. Since you're using the vlookup twice, it can be as many as 4 billion operations. Naturally, it's going to be a bit slow.

    You can turn automatic calculation off and that will allow you to make changes to the tables without it recalculating. To update the table, you'd press F9 or turn automatic calculation back on.

    A second option is to use conditional formatting to turn the font color the same as the background color if it's #N/A and then use a straight vlookup without the error checking. Of course, the #N/A values will still be in the column then.

+ Reply to Thread

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.6.0 RC 1