我需要清除同一工作簿中两张纸上的所有数据(第1行除外)。当前,一张纸有21,000行,另一张纸有10,000行,两者都有26列。
当我使用以下代码时,大约需要2.5分钟才能执行。
必须有一种更快的方法,因为我可以在不到8秒的时间内手动完成此操作。
Sub DeleteExceptFirst()
TurnOffFunctionality 'Turn off at the start
Dim StartTime As Double
StartTime = Timer 'Get start time
Dim shCount As Integer
Dim wks As Worksheet
For shCount = 1 To 2
If shCount = 1 Then
Set wks = cnCustomers
Else
Set wks = cnVendors
End If
wks.Rows("2:" & Rows.Count).ClearContents
Next shCount
TurnOnFunctionality 'Turn back on at the end
Call EndTimer("DeleteExceptFirst", StartTime)
End Sub
我为您将AcsErno的产品线整合到一个简单的循环中。
Sub deleteallbutfirstrow()
Dim ws As Worksheet
Dim starting_ws As Worksheet
Set starting_ws = ActiveSheet 'remember which worksheet is active in the beginning
For Each ws In ActiveWorkbook.Worksheets
ws.UsedRange.Offset(1).ClearContents
Next
starting_ws.Activate 'activate the worksheet that was originally active
End Sub
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句