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.
 

Ropes4u

New Member
Joined
Dec 11, 2005
Messages
46
I am using excel 2003, I have name manager but was hoping for a faster method so I could edit the names quickly.
 

jim may

Well-known Member
Joined
Jul 4, 2004
Messages
7,453
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
 

Ropes4u

New Member
Joined
Dec 11, 2005
Messages
46
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!
 

jim may

Well-known Member
Joined
Jul 4, 2004
Messages
7,453
What was different about the 10 missed range names from the other 130 (total of 140)?
 

Ropes4u

New Member
Joined
Dec 11, 2005
Messages
46
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. .
 

Forum statistics

Threads
1,081,476
Messages
5,358,908
Members
400,514
Latest member
JoHio2577

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top