我正在使用vba for Excel,以便通过以下方式将数据保存到数组中:
Dim allPosts As Variant
allPosts = Range("A2:J5000")
Run Code Online (Sandbox Code Playgroud)
之后,我正在更改allPosts数组中的数据,然后我想通过以下方式将其粘贴回来:
Range("A2:J5000").Value = allPosts
Run Code Online (Sandbox Code Playgroud)
我收到错误:
运行时错误1004应用程序定义或对象定义
并且复制在特定单元格停止,当我将此单元格中的字符串更改为更短时,问题就解决了.
谢谢
我的工作表上有大约 50 行,我正在使用 VBA 宏对其进行编辑。
当我以以下格式存储最后使用的行时
NewLastRow = ActiveSheet.UsedRange.Rows.Count
Run Code Online (Sandbox Code Playgroud)
NewLastRow 得出了第 65 行,尽管这些行中没有任何内容。
因此,我合并了一段代码来选择活动范围,并删除没有内容的行。
ActiveSheet.UsedRange.Select
'Deletes the row within the selection if the row has no data.
Dim i As Long
'Turn off aspects which could slow down process.
With Application
.Calculation = xlCalculationManual
.ScreenUpdating = False
'Delete backwards.
For i = Selection.Rows.Count To 1 Step -1
If WorksheetFunction.CountA(Selection.Rows(i)) = 0 Then
Selection.Rows(i).EntireRow.Delete
End If
Next i
.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
End With
Run Code Online (Sandbox Code Playgroud)
这确实有效,但是需要很长时间。我怎样才能加快速度?