楼主 herelazy |
Q:如何用VBA把A列的办事处,类别,款号分列? 如图所示:
A:- Sub test()
- Dim N&, Rng As Range, Rng2 As Range
- Application.ScreenUpdating = False
- For N = 34 To Cells(Rows.Count, 1).End(3).Row
- If Cells(N, 1) <> "" Then
- If Cells(N, 1).Value Like "*办" Then
- If Not Rng Is Nothing Then
- With Rng
- .Offset(1) = .Value
- Range(.Offset(1), Cells(N - 1, 1)).Merge
- End With
- End If
- Set Rng = Cells(N, 1)
- If Not Rng2 Is Nothing Then
- With Rng2
- .Offset(, 1).Resize(1, 6).Cut
- Cells(N, 3).Insert
- Range(Rng2, Cells(N - 1, Rng2.Column)).Merge
- Set Rng2 = Nothing
- End With
- End If
- ElseIf Cells(N, 1).Value Like "[0-9A-Z]*" Then
- With Cells(N, 1)
- .Offset(, 2) = .Value
- .Value = ""
- End With
- ElseIf Cells(N, 1).Value = "总计" Then
- If Not Rng2 Is Nothing Then
- With Rng2
- .Offset(, 1).Resize(1, 6).Cut
- Cells(N, 3).Insert
- Range(Rng2, Cells(N - 1, Rng2.Column)).Merge
- End With
- End If
- If Not Rng Is Nothing Then
- With Rng
- .Offset(1) = .Value
- Range(.Offset(1), Cells(N - 1, 1)).Merge
- End With
- End If
- Cells(N, 1).Resize(1, 3).Merge
- Else
- If Not Rng2 Is Nothing Then
- With Rng2
- .Offset(, 1).Resize(1, 6).Cut
- Cells(N, 3).Insert
- Range(Rng2, Cells(N - 1, Rng2.Column)).Merge
- End With
- End If
- With Cells(N, 1)
- .Offset(, 1) = .Value
- .Value = ""
- .Offset(, 2) = "合计"
- Set Rng2 = .Offset(, 1)
- End With
- End If
- End If
- Next N
- [c1].Resize(N - 2, 1).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
- Application.ScreenUpdating = True
- End Sub
分列重排.rar |