grantboshart
New Member
- Joined
- Jul 1, 2015
- Messages
- 49
Hi all,
I have a line of code that is generating the below response.
Error:
<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit;">**The name that you entered isnot valid
Reason for this:
1) The name does not begin with a letter or underscore
2) The name contains a space or other invalid character
3) The name conflicts with a Excel built in name or name of another objectin the workbook**
</code>
*nrow* and *llr* are both integers and Header is a collection containing text strings. It is getting caught up beginning at the ".Name" statement
full code below but i do not believe it is necessary. To be clear, this code works perfectly in the beta excel sheet that i created it in.
when hovering over the .Name portion of the code in debug mode, the comment box that pops up says "<application defined or object defined error>"<application-defined or="" object-defined="" error="">
any idea why it is triggering this error? no other workbooks are open.
Thanks in advance!!!</application-defined>
I have a line of code that is generating the below response.
Code:
Range("F" & nrow, "F" & llr).Name = Header(iii)
Error:
<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit;">**The name that you entered isnot valid
Reason for this:
1) The name does not begin with a letter or underscore
2) The name contains a space or other invalid character
3) The name conflicts with a Excel built in name or name of another objectin the workbook**
</code>
*nrow* and *llr* are both integers and Header is a collection containing text strings. It is getting caught up beginning at the ".Name" statement
full code below but i do not believe it is necessary. To be clear, this code works perfectly in the beta excel sheet that i created it in.
Code:
Sub Create_Headers()
Application.EnableEvents = False
Dim rng As Range
Dim Dn As Range
Dim c, x, y As Long
Dim ray() As Variant
Dim Header As New Collection
Dim fr As Long
Dim lr As Long
Dim nrow As Long
Dim llr As Long
'_______________________________________________________________
'Workbooks("Named Ranges").Activate
Set rng = Worksheets("HGL").Range(Worksheets("HGL").Range("A10"), _
Worksheets("HGL").Range("A" & Rows.Count).End(xlUp))
'ReDim ray(1 To rng.Count)
ReDim ray(1)
c = 0
For Each Dn In rng
If Not Dn = vbNullString Then
c = c + 1
Debug.Print c & " " & Dn.Value
ReDim ray(c)
ray(c) = Dn.Value
Debug.Print ray(c)
Header.Add ray(c)
Debug.Print Header.Count
Debug.Print Header(c)
End If
Next Dn
'Worksheets("Sheet1").Range("T1").Resize(c) = Application.Transpose(ray)
rayl = UBound(ray)
Debug.Print "ray has a size of " & rayl
For ii = 1 To rayl
Debug.Print Header(ii)
Next ii
lr = Range("C" & Rows.Count).End(xlUp).Row
Debug.Print "The lower bound of the used range is row " & lr
'______________________________________________________________________
For iii = 1 To rayl
Debug.Print "Header " & iii & ": which has a value of " & Header(iii)
nrow = Columns(1).Find(what:=Header(iii)).Row
Debug.Print Header(iii) & " can be found on row " & nrow
For i = nrow To lr + 1
Debug.Print Range("C" & i).Address
If Range("C" & i).Value = vbNullString Then
llr = i - 1
Exit For
End If
Next i
With Range("C" & nrow, "C" & llr)
.Name = Header(iii)
End With
Debug.Print Header(iii) & " range is located at " & Range(Header(iii)).Address
olength = Range(Header(iii)).Rows.Count
Debug.Print olength
' For i = 1 To olength
' Debug.Print Range(Header(iii))(i).Value
' Range("A" & i).Value = Range(Header(iii))(i).Value
' Next i
Next iii
'this code below inputs the summary data into a specified range.
For i = 1 To rayl
Debug.Print i & Header(i)
Debug.Print Range("K" & i).Address
Worksheets("Sheet1").Range("K" & i).Value = Header(i)
Worksheets("Sheet1").Range("L" & i).Value = Application.WorksheetFunction.Sum(Range(Header(i)))
Next i
Application.EnableEvents = True
End Sub
when hovering over the .Name portion of the code in debug mode, the comment box that pops up says "<application defined or object defined error>"<application-defined or="" object-defined="" error="">
any idea why it is triggering this error? no other workbooks are open.
Thanks in advance!!!</application-defined>
Last edited: