.png)
VBA를 사용하여 명명된 범위를 만들려고 합니다. FirstBodyCell
및 둘 다 ColumnCode
단일 셀입니다. 나는 명명된 범위가 결국 다음과 같은 것으로 정의되기를 원합니다(해당 열이 FirstBodyCell
있는 열에 따라 다름).
=Offset(Sheet1!$E$8,0,0,COUNTA(Sheet1!$E:$E)-COUNTA(Sheet1!$E$1:$E$7),1)
아래 서브를 사용하면 상승합니다.
런타임 오류 '438': 개체가 이 속성이나 메서드를 지원하지 않습니다.
그리고 가 있는 라인을 가리킵니다 .Name = ColumnCode.Value
. 이 코드에 어떤 문제가 있는지 아시나요?
Sub CreateNamedRange(FirstBodyCell As Range, ColumnCode As Range)
With ActiveWorkbook.Names
.Name = "col_" & ColumnCode.Value
.RefersToR1C1 = "=Offset(" & FirstBodyCell & ",0,0," & _
"COUNTA(" & Columns(FirstBodyCell.Column) & ")-COUNTA(" & _
Range(Cells(1, FirstBodyCell.Column), FirstBodyCell.Offset(-1, 0)) & _
"),1)"
End With
End Sub
답변1
Workbook.Names
, , 및 Names
같은 멤버를 노출하는 컬렉션 클래스를 생성하는 속성입니다 .Add
Count
Parent
Item
개체 에 속성이나 멤버가 Names
없습니다 (따라서 오류 438 - 개체에서 멤버/속성을 지원/노출하지 않습니다).Name
RefersToR1C1
해당 개체의 멤버를 호출하려고 합니다 Add
. 해당 함수는 할당하려는 값을 매개 변수로 사용합니다. 또한 .Address
R1C1 형식이 아닌 주소를 반환합니다. RefersTo
대신 사용해 보세요 RefersToR1C1
.
With ActiveWorkbook.Names.Add( _
Name:="col_" & ColumnCode.Value, _
RefersTo:="=Offset(" & FirstBodyCell & ",0,0," & _
"COUNTA(" & Columns(FirstBodyCell.Column) & ")-COUNTA(" & _
Range(Cells(1, FirstBodyCell.Column), FirstBodyCell.Offset(-1, 0)) & _
"),1)")
'the With block variable is the Name object that was created+added to the Names collection:
Debug.Print .Name
End With
메모스캇 크라이너.Address
거기에 제공하는 객체 중 를 사용하고 싶을 것이므로 Range
실제 값은 RefersToR1C1
다음과 같습니다.
RefersTo:="=Offset(" & FirstBodyCell & ",0,0," & _
"COUNTA(" & Columns(FirstBodyCell.Column).Address & ")-COUNTA(" & _
Range(Cells(1, FirstBodyCell.Column), FirstBodyCell.Offset(-1, 0)).Address & _
"),1)")