这个问题在这里已有答案:
所以我从这里使用自动填充宏,或下面的代码: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行中运行良好,但在将其应用于较大的数据集时会出现运行时错误。有没有wya这个代码可以针对更大的数据进行优化?
更换:
Dim xRow As Integer, xCol As Integer
有:
Dim xRow As Long, xCol As Long