+ Reply to Thread
Results 1 to 18 of 18

replace all defined range names in the sheet that start with "Street" to "Road"

  1. #1
    Forum Contributor
    Join Date
    06-07-2008
    Posts
    126

    replace all defined range names in the sheet that start with "Street" to "Road"

    Hi everyone!

    I want to replace all defined range names in the sheet that start with "Street" to "Road"

    For example I have 50 defined names in the sheet as such "Street-01", "Street-02"... all through "Street-50"

    I want to change them all in vba to Road-01", "Road-02" etc.

    Thanks.

  2. #2
    Valued Forum Contributor
    Join Date
    06-16-2006
    Location
    Sydney, Australia
    MS-Off Ver
    2013 64bit
    Posts
    1,394
    Try this
    Please Login or Register  to view this content.
    Last edited by Leith Ross; 06-14-2008 at 06:56 PM. Reason: You did not add code tags

  3. #3
    Forum Contributor
    Join Date
    06-07-2008
    Posts
    126
    Thanks Mallycat

    A slight problem.

    The line:
    Application.Goto Reference:=myOldName
    is giving me the following error "Reference is not valid"

    Also The Street names do not have to be sequential or even ending with two digits. Some are "Street_a97" for example. What I want is to replace the "Street_" part by the "Road_" part only, leaving the rest of the string the same. (i.e. Road_a97")

    Hope you can help

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

    Here is macro to change the range names.
    Please Login or Register  to view this content.
    Adding the Macro
    1. Copy the macro above pressing the keys CTRL+C
    2. Open your workbook
    3. Press the keys ALT+F11 to open the Visual Basic Editor
    4. Press the keys ALT+I to activate the Insert menu
    5. Press M to insert a Standard Module
    6. Paste the code by pressing the keys CTRL+V
    7. Make any custom changes to the macro if needed at this time
    8. Save the Macro by pressing the keys CTRL+S
    9. Press the keys ALT+Q to exit the Editor, and return to Excel.

    To Run the Macro...
    To run the macro from Excel, open the workbook, and press ALT+F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.

    Sincerely,
    Leith Ross

  5. #5
    Valued Forum Contributor
    Join Date
    06-16-2006
    Location
    Sydney, Australia
    MS-Off Ver
    2013 64bit
    Posts
    1,394
    Mm, that looks like a good solution

  6. #6
    Forum Contributor
    Join Date
    06-07-2008
    Posts
    126
    Hi Leith

    Looked like it was going to work, but no changes were made to the names!

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

    interesting, it ran fine on my test sheet. I am using Excel 2003. Are you using a different version of Excel?

    Sincerely,.
    Leith Ross

  8. #8
    Forum Contributor
    Join Date
    06-07-2008
    Posts
    126
    Excel 2002. Also tried in on Excel 2007

    See attached sample file.
    Attached Files Attached Files

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

    Got it fixed. Here is the revised macro. It has been added to the workbook also.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross
    Attached Files Attached Files

  10. #10
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    Looks like a small error in Leith's code

    This works on your attached book

    Please Login or Register  to view this content.
    Oops Leith posted a fix 1st
    Please Read Forum Rules Before Posting
    Wrap VBA code by selecting the code and clicking the # icon or Read This
    How To Cross Post politely

    Top Excel links for beginners to Experts

    If you are pleased with a member's answer then use the Scales icon to rate it
    If my reply has assisted or failed to assist you I welcome your Feedback.

  11. #11
    Forum Contributor
    Join Date
    06-07-2008
    Posts
    126
    mudraker and Leith

    Excellent! Both codes worked like a charm.

    Thanks so much and have a great day/evening

  12. #12
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    Leith

    For you Info

    I am using 2003 & your original version did not work for me

    matrex

    thanks for the feedback

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

    My typing skills aren't the best. Sometimes my transcriptions from my workbook to the forum are incomplete. I try to be vigilant in catching those errors, but some slip by. I appreciated the help from both of you and your patience.

    Sincerely,
    Leith Ross

  14. #14
    Registered User
    Join Date
    05-14-2014
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: replace all defined range names in the sheet that start with "Street" to "Road"

    Hi... say i have a set of name ranges from rows 1 to 10, and columns A to Z.

    I replicated this to rows 20 to 50 and columns A to Z

    For this replication, i would like to change the range name by adding _case2... but only the name ranges that falls within rows 20 to 50 and columns A to Z.... how do I embed this in the macro??

    Please help

    Kind regards
    Chris

  15. #15
    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: replace all defined range names in the sheet that start with "Street" to "Road"

    Hello Chris,

    Welcome to the Forum!

    Can you give an example of the cell names you are using?
    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!)

  16. #16
    Registered User
    Join Date
    05-14-2014
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: replace all defined range names in the sheet that start with "Street" to "Road"

    Okay...

    Say from A1:J1 and A10:J10 i have a few name ranges called AAA, BBB, CCC, obviously theres 9 other name range in that block, I duplicated this to apply to A11:J11 and A20:J20. So its still carrying the same name range

    I would like to change this name range which i replicated to AAA_case2, BBB_case2, CCC_case2

    Rather than using Ctrl H to find and replace those selected rows.... i would like a macro to do this for me so it saves me time
    Is this workable?

  17. #17
    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: replace all defined range names in the sheet that start with "Street" to "Road"

    Hello Chris,

    This should do it...
    Please Login or Register  to view this content.

  18. #18
    Registered User
    Join Date
    08-05-2004
    Posts
    2

    Re: replace all defined range names in the sheet that start with "Street" to "Road"

    This worked for me...thank you Leith!

+ 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