在自动填充空白值的宏上获取运行时错误 6 [重复]
Posted
技术标签:
【中文标题】在自动填充空白值的宏上获取运行时错误 6 [重复]【英文标题】:Getting a run time error 6 on Macro that autofills blank values [duplicate] 【发布时间】:2019-03-04 15:12:31 【问题描述】:所以我在这里使用自动填充宏,或者下面的代码:https://www.extendoffice.com/documents/excel/3974-excel-repeat-a-value-until-new-value-is-seen.html
Sub FillDown()
Dim xRng As Range
Dim xRows As Long, xCols As Long
Dim xRow As Integer, xCol As Integer
Set xRng = Selection
xCols = xRng.Columns.CountLarge
xRows = xRng.Rows.CountLarge
For xCol = 1 To xCols
For xRow = 1 To xRows - 1
If xRng.Cells(xRow, xCol) <> "" Then
xRng.Cells(xRow, xCol) = xRng.Cells(xRow, xCol).Value
If xRng.Cells(xRow + 1, xCol) = "" Then
xRng.Cells(xRow + 1, xCol) = xRng.Cells(xRow, xCol).Value
End If
End If
Next xRow
Next xCol
End Sub
我的数据中有大约 300,000 行。该宏在 1000 行上运行良好,但在将其应用于更大的数据集时出现运行时错误。有没有什么方法可以针对更大的数据优化这段代码?
【问题讨论】:
【参考方案1】:替换:
Dim xRow As Integer, xCol As Integer
与:
Dim xRow As Long, xCol As Long
【讨论】:
以上是关于在自动填充空白值的宏上获取运行时错误 6 [重复]的主要内容,如果未能解决你的问题,请参考以下文章