VBA to create new range from list

Ropes4u

New Member
Joined
Dec 11, 2005
Messages
46
I have two sheets for two different pieces of equipment with the exception of the sheetname the sheets identical. I would like to copy the range names between the sheets changing only the first two characters. My current list is the top block of characters while the second block of charactrs is what I would like to create. there are 140~ range names per sheet. Alternatively if there is a better way to name the ranges I am open to changing the names again. the ranges (names) are used in other VBA and as references between sheets and workbooks.

Column A Column B
Name Refers to
b1day21x0ct ='Front page Block1'!$E$52
b1day21x0db ='Front page Block1'!$G$52
b1day21x0evaps ='Front page Block1'!$F$52
b1day21x0minload ='Front page Block1'!$D$52
b1day21x0total ='Front page Block1'!$H$52


b2day21x0ct ='Front page Block2'!$E$52
b2day21x0db ='Front page Block2'!$G$52
b2day21x0evaps ='Front page Block2'!$F$52
b2day21x0minload ='Front page Block2'!$D$52
b2day21x0total ='Front page Block2'!$H$52

Thank You.
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
I am using excel 2003, I have name manager but was hoping for a faster method so I could edit the names quickly.
 
Upvote 0
Well, I finally got it going -- Here's the code to duplicate the range names (with modifications) based on your small example ONLY.

Let me know your thoughts please. Jim

Code:
Sub DupRangeNames() 'assumes pre-existence of sheets: Front Page Block1 and Front Page Block2
Dim Cadd As String, FullNameData As String
For i = 1 To ActiveWorkbook.Names.Count
  Cadd = ActiveWorkbook.Names(i)
  Cadd = WorksheetFunction.Substitute(Cadd, "Block1", "Block2")
  FullNameData = Names(i).Name
  FullNameData = WorksheetFunction.Substitute(FullNameData, "Block1", "Block2", 1)
  FullNameData = WorksheetFunction.Substitute(FullNameData, "b1day", "b2day", 1)
  ActiveWorkbook.Names.Add Name:=FullNameData, RefersTo:=Cadd
Next
End Sub
 
Upvote 0
Jim

the macro missed about 10 names which I corrected manually, worked like a charm. I still wish I could figure out how to create/edit the names from a sheet. When I finish this projecy that could become my next obsession..

Thank You very much!
 
Upvote 0
What was different about the 10 missed range names from the other 130 (total of 140)?
 
Upvote 0
Re: VBA to create new range from list - Solved

10-15 of the range names had a "b1" in stead of "b2" as the first two characters. I probably messed something up but I have not freed myself from email long enough to dig into the cause yet. .
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,291
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top