Excel&VBA/VBA
VBA) 그룹 자동화
센텀Dev
2022. 10. 7. 11:01
그룹
dim idx_1 as long
dim idx_2 as long
dim sRow as long
dim LastRow as long
dim TargetSheet as Worksheet
set TargetSheet = Sheets("쉬트명")
TargetSheet.Select
--처리행 구하기
LastRow = TargetSheet.Range("a65536").End(xlUp).Row
Application.ScreenUpdating = False
With ActiveSheet.Outline
.AutomaticStyles = false
.SummaryRow = xlAbove
.SummaryColumn = xlRight
End With
For idx_1 = 2 To LastRow
If cells(idx_1, 1) = "" Then Exit For
If Cells(idx_1,1) = "T" Then sRow = idx_1 +1
If Cells(idx_1 + 1, 1) = "T" or Cells(idx_1,1) = "" Then
If sRow < idx_1 Then
Rows(Trim(Str$(sRow)) & ";" & Trim(Str$(idx_1))).Select
Selection.Rows.Group
End if
End if
Next idx_1
ActiveSheet.Outline.ShowLevels RowLevels:=1
ActiveWindow.ScrollRow = 2
그룹해제
Sheets("쉬트명").Select
Application.ScreenUpdating = False
ActiveSheet.Outling.ShowLevels RowLevels:=2
Cells.Select
On Error Resume Next
Selection.Rows.Ungroup
On Error GoTo 0
ActiveWindow.ScrollRow = 2