+ Reply to Thread
Results 1 to 7 of 7

Replacing numbers into a string?

  1. #1
    Registered User
    Join Date
    04-26-2013
    Location
    Boston
    MS-Off Ver
    Excel 2003 - Can access others if needed
    Posts
    4

    Replacing numbers into a string?

    Hello,

    New to VBAs, but some Excel knowledge, CSS, HTML, and basic a long, long time ago.

    I am trying to replace certain characters in a URL with zip codes. I hope to generate a long list of URLs that are the same except for the five characters that make up the zip code--so each cell will look exactly the same except for the zip code portion of the URL string.

    Here is an example of the characters that need to be replaced with a different Zip code each time: http://hermanmiller.com/dealer-locator?location=02133&product_name=
    Note this is not the URL I'm talking about.

    So, the workflow I imaging is as follows:

    1. Excel locates five character zip code string within URL in A1 on sheet 1.
    2. Excel locates zip code in A1 on sheet 2 and copies to clip board
    3. Excel selects zip code string in URL and replaces it with the data in A1 on sheet 2
    4. Excel duplicates URL A1 on sheet 1 into A2
    5. Repeat, except replacing zip code pulled from A2sheet2 instead of A1sheet2

    So far the only progress I've made is to make "sheet 2" which has a list of all US zip codes. Appreciate any help!
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: Replacing numbers into a string?

    silvergrahm,

    Welcome to the Excel Forum.

    The only 5 character zip code on Sheet2 is 02133.

    There is no 5 character zip code 02133 in Sheet1.

    Are you looking to change the 5 character zip code on Sheet2 to 02133-#### ?

    If so, then please post another workbook that contains in Sheet1 the five character and the 02133-#### zip codes.

    Then it will be easy to do what you require.
    Have a great day,
    Stan

    Windows 10, Excel 2007, on a PC.

    If you are satisfied with the solution(s) provided, please mark your thread as Solved by clicking EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

  3. #3
    Registered User
    Join Date
    04-26-2013
    Location
    Boston
    MS-Off Ver
    Excel 2003 - Can access others if needed
    Posts
    4

    Re: Replacing numbers into a string?

    Hi Stan, I have excel 03 for Mac, so perhaps something is not working? I downloaded my own attachment and it works for me, the way I saved it. Does sheet 1 show a list of website addresses that are exactly the same? Does sheet 2 show a list of 5 digit numbers?

    Let me explain what I want to do a little bit better. I am trying to (ethically, w/ low bandwidth) "scrape" data from one of those online locators with an embedded map. I have found that I can make a scraper in Outwit Hub that will harvest the info I need from each page that is generated per zip code query. So, I figure I will be able to get all of the info I need if I compile a list of URLs for that page that correspond to thousands of searches, one for each US zip code, and then run my scraper on each of these URLs, one by one.

    I'm not going to show you which exact URL I want to scrape, so I am using an example URL that is the same as the real site I am talking about for all folders except the actual domain. That example is: http://hermanmiller.com/dealer-locat...&product_name= Don't bother clicking it because it doesn't exist.

    The 5 character string exists in red here: http://hermanmiller.com/dealer-locator?location=#####&product_name= On this particular URL, you can input any five digit US zip code, and the site will return a search for dealers within and around that geographic location. I was just using 02133 as an example.

    I want to make a macro that will make me a list of URLs that are equivalent to me searching every single five digit US zip code on that site. I figure the best way to do this is to have one sheet with the URL, and another with a list of us Zip codes. I need excel to locate the five character string in the URL above (#####) and replace it with a real zip code, and then do it over again for another zip code, and then another. I know it must be fairly easy, but I'm at a loss how to even start.

    EDIT: The site automatically truncated the URL, apparently. You can view the full URL if you open it in a new window.
    Last edited by silvergrahm; 04-26-2013 at 09:59 PM.

  4. #4
    Forum Contributor
    Join Date
    10-13-2012
    Location
    Southern California
    MS-Off Ver
    Excel 2007
    Posts
    401

    Re: Replacing numbers into a string?

    How about this solution?

    No VBA required.

    zip_VBA_example - modified.xlsx

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Replacing numbers into a string?

    Hello silvergrahm,

    This macro will take the single URL in "A1" on "Sheet1" and add the ZIP to it from "A1" on "Sheet2". The URL will be copied into "A2" on "Sheet1" and the ZIP from "A2" "Sheet2" will be inserted. This will continue until there are no more ZIP codes on Sheet2.

    A button has been added to "Sheet1" to run the macro.

    NOTE: Sorry, I just realized this for a MAC. The Mac does not support Regular Expressions and this code will not run.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by Leith Ross; 04-26-2013 at 10:33 PM.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  6. #6
    Registered User
    Join Date
    04-26-2013
    Location
    Boston
    MS-Off Ver
    Excel 2003 - Can access others if needed
    Posts
    4

    Re: Replacing numbers into a string?

    Thanks so much! I have ways to get to windows version of excel @ work so I should be able to work things out. I can understand this code a bit so hopefully I will be able to use it elsewhere in the future. Also I can't open the xlsx file right now, but I'll be able to soon.

  7. #7
    Forum Contributor
    Join Date
    10-13-2012
    Location
    Southern California
    MS-Off Ver
    Excel 2007
    Posts
    401

    Re: Replacing numbers into a string?

    If you can't open the xlsx file, here's an xls version of the program:

    zip_VBA_example - modified.xls

+ 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