每天学点excel
[群友求助]非数值类内容如何实现自动分级显示?
Excel中对于数值类内容,依据汇总关系可以实现自动分级显示,对于非数值类内容能否实现自动分级显示?
VBA实现:
Sub 按级别自动生成分级显示() Dim ws As Worksheet Dim lastRow As Long Dim i As Long Dim lvl As Variant Set ws = ActiveSheet Application.ScreenUpdating = False ws.Cells.ClearOutline ws.Outline.SummaryRow = xlSummaryAbove lastRow = ws.Cells(ws.Rows.Count, "C").End(xlUp).Row If lastRow < 2 Then MsgBox "未在 C 列检测到级别数据!", vbExclamation GoTo 收尾 End If For i = 2 To lastRow lvl = ws.Cells(i, "C").Value If IsNumeric(lvl) Then If CInt(lvl) >= 1 And CInt(lvl) <= 8 Then ws.Rows(i).OutlineLevel = CInt(lvl) End If End If Next i ws.Outline.ShowLevels RowLevels:=4收尾: Application.ScreenUpdating = True ' MsgBox "完成!共处理第2行~第" & lastRow & "行。" & vbCrLf & _ "点左上角 1/2/3/4 按钮即可快速折叠展开。", vbInformationEnd Sub
Excel源文件:
通过网盘分享的文件:20261127设备.zip链接: 网页链接 提取码: dk4m
官方网站:网页链接
