답변1
매크로의 VBA 스크립트를 사용해 보는 것은 어떨까요?
나는 이것이 도움이 될 것이라고 생각합니다: Worksheets("Sheet1").Rows(i).OutlineLevel
시트를 살펴보고 이 속성을 셀에 씁니다.
답변2
내 응용 프로그램에서 출력된 개요 수준을 적절하게 사용하려는 경우와 똑같은 상황이 있습니다. 그런 다음 Excel에서 Visual Basic 스크립트를 만들어야 합니다. vb-script 편집기는 매크로 편집기를 통해 접근할 수 있습니다. 레벨을 포함할 추가 두 번째 열을 삽입한 다음 파일을 통과하여 올바른 레벨로 열을 채우는 일반적인 코드는 다음과 같습니다.
Sub GetOutlineLevel()
' Initiate where to start. With a header row, typical start is row 2
RowCount = 2
' Insert a new column B, write "Level" as the title in row 1,
' and define the width of the column
Columns("B:B").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Cells(1, 2).Value = "Level"
Columns("B:B").Select
Selection.ColumnWidth = 5
' Go to the first row you want to analyze
Cells(RowCount, 1).Activate
' Make a loop to go through all lines that contains data.
' This assumes that there is a continuous row of lines that all have data in the
' first column
Do
' Fill the cell in column 2 at the current row with the outline level
Cells(RowCount, 2).Value = ActiveCell.Rows.OutlineLevel
' Go to the next row
RowCount = RowCount + 1
Cells(RowCount, 1).Activate
' Continue and stop at the first empty row
Loop Until ActiveCell.Value = ""
End Sub
그런 다음 다른 기능으로 확장할 수도 있습니다. 위 루프에서 가장 높은 개요 레벨을 추적하고 레벨 수만큼 추가 열을 만든 다음 레벨 구조가 시각화될 수 있도록 이러한 각 열에 몇 가지 논리를 만들었습니다.
열 삽입은 다음과 같습니다(여기에는 "X"가 포함된 셀을 검정색으로 만드는 조건부 서식 설정이 포함됨).
ColumnsInserted = 0
Do
Columns("C:C").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Cells(1, 3).Value = "L" & MaxLevel - ColumnsInserted
Columns("C:C").Select
Selection.ColumnWidth = 4
Columns("C:C").Select
Selection.FormatConditions.Add Type:=xlTextString, String:="X", _
TextOperator:=xlContains
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorLight1
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
ColumnsInserted = ColumnsInserted + 1
Loop Until ColumnsInserted = MaxLevel
마지막으로 레벨 열에 대한 검사를 통해 추가 열의 모든 셀을 채우고 올바른 셀에 "X"를 넣는 이중 루프 시퀀스입니다. 이 코드는 다음과 같습니다.
FIns = 1
Do
RowCount = 2
Do
Cells(RowCount, 2 + FIns).Select
ActiveCell.FormulaR1C1 = "=IF(RC[-" & FIns & "]=" & FIns & ",""X"","""")"
RowCount = RowCount + 1
Loop Until Cells(RowCount, 1).Value = ""
FormulaInsert = FormulaInsert + 1
Loop Until FormulaInsert > MaxLevel
위 코드의 좋은 들여쓰기가 최종 게시물에서 망가진 것을 알 수 있지만, 일부 코딩에 익숙하다면 이를 좋은 방법으로 정리할 수 있을 것입니다.
답변3
네, 가능합니다. 이 기능이 GET.CELL()
도움이 될 것입니다.
GETCELL
특별한 기능이에요. 실제로 Excel 4 매크로 기능이므로 파일을 사용할 때 파일을 .xlsm-File로 저장해야 합니다. 추가 정보여기
OutlineLevel
다음 수식을 사용하여 시트 상단 셀(예: A1)에 명명된 범위(예: )를 정의합니다 .=GET.CELL(28,Sheet1!A1)
- 빈 열에서 이 명명된 범위(
=OutlineLevel
)를 참조하고 수식을 복사하세요.
해당 행의 계층 구조 수준을 가져옵니다.
GlennUK가 제안한 꽤 오래된 솔루션에 찬사를 보냅니다.Mr.Excel 포럼