|
楼主 |
发表于 2024-7-12 03:38
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
程序优化
If FirstRow < Rng.Row Then
Exit Function
End If
- Function MergeRng(Rng As Range)
- Dim LastRow, FirstRow
- Dim ii, jj
- Dim Sht As Worksheet
- Set Sht = Rng.Parent
- With Rng.Parent
- LastRow = Rng.Row + Rng.Rows.Count - 1
- For ii = Rng.Row + Rng.Rows.Count - 1 To 2 Step -1
- Debug.Print .Cells(ii, Rng.Column).Address
- 'Debug.Print Rng.Address
-
-
- If .Cells(ii, Rng.Column).Value <> .Cells(ii - 1, Rng.Column).Value Then
- FirstRow = ii
- If FirstRow < Rng.Row Then
- Exit Function
- End If
- .Cells(FirstRow, Rng.Column).Resize(LastRow - FirstRow + 1, 1).Merge
- LastRow = ii - 1
- End If
- Next ii
- End With
- End Function
复制代码
- <p>
- </p><p>Private Sub deldeldeldeldelde()</p><p> Application.DisplayAlerts = False</p><p> Dim Rng As Range, oRng As Range</p><p> Set Rng = Selection</p><p> Dim Sht As Worksheet</p><p> Set Sht = Rng.Parent</p><p> With Sht</p><p> Set Rng = .Range(.Cells(4, 1).Formula)</p><p> Debug.Print Rng.Address</p><p> Set oRng = Rng(3, 1).Resize(Rng.Rows.Count - 2, Rng.Columns.Count)</p><p> For jj = 1 To 3</p><p> 'Set oRng = oRng(, 3).Resize(oRng.Rows.Count, 1)</p><p> MergeRng oRng(, jj).Resize(oRng.Rows.Count, 1)</p><p> Next jj</p><p> </p><p> End With</p><p> Application.DisplayAlerts = True</p><p>End Sub</p><p></p>
复制代码
|
|