我正在尝试通过复制和粘贴来修复1600行数据库,但是下面的代码很慢。关于如何加快速度的任何想法?
Sub copy()
Dim ws As Worksheet
Dim i As Long
Application.ScreenUpdating = False
Set ws = Sheets("UK File Cash Mod")
For i = 2 To 1600
If ws.Cells(i, 1) Like "384*" And Cells(i + 1, 1) = "" Then
ws.Cells(i, 1).copy
If ws.Cells(i + 1, 3) <> "" Then
ws.Cells(i + 1, 1).PasteSpecial
ws.Cells(i, 2).copy
ws.Cells(i + 1, 2).PasteSpecial
End If
Else
End If
Next i
Application.ScreenUpdating = True
End Sub
答案 0 :(得分:2)
我通过一个简单的Destination.Value=Source.Value
删除了所有复制粘贴,所以您得到了:
Sub copy()
Dim ws As Worksheet
Dim i As Long
Application.ScreenUpdating = False
Set ws = Sheets("UK File Cash Mod")
For i = 2 To 1600
If ws.Cells(i, 1) Like "384*" And Cells(i + 1, 1) = "" Then
If ws.Cells(i + 1, 3) <> "" Then
ws.Cells(i + 1, 1).Value = ws.Cells(i, 1).Value
ws.Cells(i + 1, 2).Value = ws.Cells(i, 2).Value
End If
Else
End If
Next i
Application.ScreenUpdating = True
End Sub