Hello All,
I have written a macro to (try to) create a non-contiguous named range in a worksheet containing 10,000+ lines of data.
Each of the 268 non-contiguous ranges is in column C and is 10 rows deep by 1 column wide starting at each cell containing "Process Components".
The main part of the code seems to work fine but when I try to add the non-contiguous range to a name I get an "Application-defined or object-defined error".
Can someone tell me why I get the "Application-defined or object-defined error" on the line that adds the name HRRange to the Newrange range? I have looked at this problem too long to see any errors now
Thanks for your help!
[pre]
[/pre]
I have written a macro to (try to) create a non-contiguous named range in a worksheet containing 10,000+ lines of data.
Each of the 268 non-contiguous ranges is in column C and is 10 rows deep by 1 column wide starting at each cell containing "Process Components".
The main part of the code seems to work fine but when I try to add the non-contiguous range to a name I get an "Application-defined or object-defined error".
Can someone tell me why I get the "Application-defined or object-defined error" on the line that adds the name HRRange to the Newrange range? I have looked at this problem too long to see any errors now
Thanks for your help!
[pre]
Code:
Sub HR_Range()
Application.ScreenUpdating = False
Dim UR As Long
Dim HRR As Range
Dim Newrange As Range
Set HRR = Sheets(6).Range(Cells(15, 3), Cells(46, 3))
Names.Add Name:="HRRange", RefersTo:=HRR
UR = Sheets(6).UsedRange.Rows.Count
For x = 46 To UR
For y = 0 To 9
If Cells(x - y, 3) = "Process Components" Then
Set Newrange = Application.Union(Newrange, Range(Cells(x, 3)))
End If
Next y
Next x
Names("HRRange").Delete
Names.Add Name:="HRRange", RefersTo:=Newrange
Application.ScreenUpdating = True
End Sub