I am currently working within a tab with named ranges. They are all associated with class 1. I would like to duplicate these cells twice, creating identical columns for classes 2 and 3. The named ranges should remain the same aside from a _2/_3 attached for the next two classes. I also need the formulas to be changed within each column, but containing the correct suffix(_2/_3).
This is a simplified version to better explain what I am trying to do:
**Class 1**
Lives
Age
Adjust
Claim
Risk
**Class1 Class2 Class3**
Lives Lives_2 Lives_3
Age Age_2 Age_3
Adjust Adjust_2 Adjust_3
Claim Claim_2 Claim_3
Risk Risk_2 Risk_3
These are representative of the names of the cells; they all also contain formulas linking within each class. The class 1 area that is already completed has 9 columns and 120 rows. I would like class two to populate column 10 to 18 and class 3 the next 9. Here is the code I was working with to try to just change the names but I was unsuccessful:
Sub ChangeNames()
Dim OldName As String
Dim NewName2 As String
Dim NewName3 As String
Dim rng As Range
For r = 1 To 127
For c = 1 To 10
If IsNamedRange(Cells(r, 1 + c)) Then
Set rng = Sheets("Medical").Cells(r, 1 + c)
OldName = rng.Name
NewName2 = OldName & "_2"
NewName3 = OldName & "_3"
Sheets("Medical").Cells(r, 11 + c).Name = NewName2
Sheets("Medical").Cells(r, 21 + c).Name = NewName3
End If
Next c
Next r
End Sub
Function IsNamedRange(MyRange) As Boolean
Dim vntName As Variant
On Error Resume Next
IsNamedRange = MyRange.Name <> ""
Exit Function
End Function
Is this possible with VBA? Any help would be much appreciated!
Sub names() Dim this As String Dim OldName As String Dim NewName2 As String Dim NewName3 As String Dim x As Integer Dim y As Integer
For Each this In Workbook.names
If Range(this).Worksheet = "Medical" Then
NewName2 = Range(this).Name & "_2"
NewName3 = Range(this).Name & "_3"
x = Range(this).Column
y = Range(this).Row
Sheets("Medical").Cells(x, 10 + y).Name = NewName2
Sheets("Medical").Cells(x, 20 + y).Name = NewName3
End If
Next this
End Sub
*n*
columns over with thename_*x*
– Scott Holtzman