|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 baofa2 于 2024-4-28 16:05 编辑
- Sub test1() '无模拟附件 不再参与了 一改就乱 一审就烦
- Dim ar, wks As Worksheet
- Dim i As Long, j As Long, colSize As Long, posRow As Long
-
- Application.ScreenUpdating = False
-
- Set wks = ActiveSheet
- ar = wks.Range("A1").CurrentRegion
- posRow = UBound(ar) + 1
- colSize = UBound(ar, 2)
-
- For i = UBound(ar) To 1 Step -1
- If ar(i, 1) = "品名" Then
- With wks
- With .Sort
- With .SortFields
- .Clear
- .Add Key:=wks.Cells(i, 2), SortOn:=0, Order:=1, DataOption:=0
- For j = 3 To UBound(ar, 2)
- If Len(ar(i, j)) Then
- .Add Key:=wks.Cells(i, j), SortOn:=0, Order:=2, DataOption:=0
- End If
- Next
- .Parent.SetRange wks.Cells(i, 1).Resize(posRow - i, colSize)
- .Parent.Header = xlYes
- .Parent.Apply
- .Clear
- End With
- End With
- End With
- posRow = i
- End If
- Next
-
- Set wks = Nothing
- Application.ScreenUpdating = True
- Beep
- End Sub
复制代码
|
评分
-
1
查看全部评分
-
|