实现功能:当excel某列j从第三行开始,与上行值不同时,在当前行与上行间插入空行
代码如下:i对应当前操作行,j对应excel的列数j可以根据需要修改:
Sub insertRow()
' insertRow Macro
' 宏由 mike 录制,时间: 2012-8-6
' 快捷键: Ctrl+u
Dim RowN As Integer
Dim i As Integer,j As Integer
j = 1
For i = 1 To 20000 '判定非空的最大行数RowN
If Cells(i, j).Value <> "" Then
RowN = i
End If
Next i
For i = RowN To 3 Step -1
If Cells(i, j) <> "" And (Cells(i, j) <> Cells(i - 1, j)) And Cells(i - 1, j) <> "" Then
Rows(i).Select
Selection.Insert Shift:=xlDown
End If
Next i
End Sub
转载于:https://blog.51cto.com/mikehopes/956880