|
楼主 |
发表于 2024-8-13 15:39
|
显示全部楼层
本帖最后由 神秘风暴 于 2024-8-13 15:46 编辑
自己改来改去,这样子,功能实现了,不知道对不对,哈哈!
- Sub InsertRow() '//24-08-03
- 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("B" & Rows.Count).End(xlUp).Row
- 'Debug.Print maxrow
- MaxColumn = SH.Cells(1, Columns.Count).End(1).Column
- arr = SH.Range("a1", Cells(MaxRow, MaxColumn))
- ReDim brr(1 To 1048576, 1 To MaxColumn)
- For i = 3 To MaxRow '//从第三行开始
- If Len(arr(i, 3)) > 0 And Len(arr(i, 4)) > 0 Then '如果C列和D列不为空
- arr(i, 8) = arr(i, 8) / 3 '所用的时间姓名A与B与C平均
- 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, 3) = brr(n - 1, 4)
- brr(n, 8) = brr(n - 1, 8) * 2
- brr(n - 1, 3) = Empty: brr(n - 1, 4) = Empty: brr(n, 4) = Empty
- ElseIf Len(arr(i, 3)) > 0 Then
- arr(i, 8) = arr(i, 8) / 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, 8) = brr(n - 1, 8)
- 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.[A3].Resize(n, MaxColumn) = brr
- Application.ScreenUpdating = True '//恢复屏幕刷新
- Application.DisplayAlerts = True '//恢复系统提示
- MsgBox "一共用时:" & Format(Timer - t, "#0.0000") & " 秒," & "请查看结果!", , "系统提示!!" '//提示所用时间
- End Sub
复制代码 |
|