在自动填充空白值的宏上出现 运行 时间错误 6
Getting a run time error 6 on Macro that autofills blank values
所以我使用这里的自动填充宏,或下面的代码: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 行中运行良好,但在将其应用于更大的数据集时出现 运行 时间错误。是否可以针对更大的数据优化此代码?
替换:
Dim xRow As Integer, xCol As Integer
与:
Dim xRow As Long, xCol As Long
所以我使用这里的自动填充宏,或下面的代码: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 行中运行良好,但在将其应用于更大的数据集时出现 运行 时间错误。是否可以针对更大的数据优化此代码?
替换:
Dim xRow As Integer, xCol As Integer
与:
Dim xRow As Long, xCol As Long