代码如下。。。
Sub cmdInsertRow0811()
Application.ScreenUpdating = False '//关闭屏幕刷新
Application.DisplayAlerts = False '//关闭系统提示
Dim SH As Worksheet
Dim t
t = Timer '//开始时间
Set SH = Sheets("台账")
If SH.FilterMode Then SH.ShowAllData
maxrow = SH.Range("C" & Rows.Count).End(xlUp).Row
maxcolumn = SH.Cells(1, Columns.Count).End(1).Column
arr = SH.Range("a1", Cells(maxrow, maxcolumn))
ReDim brr(1 To 100000, 1 To maxcolumn)
For i = 2 To maxrow
If Len(arr(i, 3)) > 0 Then '如果C列不为空
arr(i, 12) = arr(i, 12) / 2 '所用的时间姓名A与B平均
For k = 1 To 2
n = n + 1
For j = 1 To UBound(arr, 2)
brr(n, j) = arr(i, j)
Next
Next
brr(n, 2) = brr(n - 1, 3)
brr(n, 12) = brr(n - 1, 12)
brr(n, 3) = Empty: brr(n - 1, 3) = Empty
Else
n = n + 1
For j = 1 To UBound(arr, 2)
brr(n, j) = arr(i, j)
Next
End If
Next
SH.[a2].Resize(n, maxcolumn) = brr
Application.ScreenUpdating = True '//恢复屏幕刷新
Application.DisplayAlerts = True '//恢复系统提示
MsgBox "一共用时:" & Format(Timer - t, "#0.0000") & " 秒," & "请查看结果!", , "系统提示!!" '//提示所用时间
End Sub
|