Where I work, Excel 2007 is still being used. When doing autofill on workbooks with thousands of rows, you get an error stating "Selection is too large" because of the 8192 different areas in the special cells range issue. I found code online (by Dave Peterson by way of Ron De Bruin) that will work around this using a Do While loop on 8000 rows at a time, but it fills the rows with values. I need something that fills each blank with the FORMULA from the cell above. Any examples would be greatly appreciated. Code is below. Much Thanks
Code:
Dim wks As Worksheet
Dim rng As Range
Dim rng2 As Range
Dim LastRow As Long
Dim col As Long
Dim lRows As Long
Dim lLimit As Long
Dim lCount As Long
On Error Resume Next
lRows = 2 'starting row
lLimit = 8000
Set wks = ActiveSheet
With wks
col = ActiveCell.Column
Set rng = .UsedRange 'try to reset the lastcell
LastRow = .Cells.SpecialCells(xlCellTypeLastCell).Row
Set rng = Nothing
lCount = .Columns(col).SpecialCells(xlCellTypeBlanks).Areas(1).Cells.Count
If lCount = 0 Then
MsgBox "No blanks found in selected column"
Exit Sub
ElseIf lCount = .Columns(col).Cells.Count Then
MsgBox "Over the Special Cells Limit" 'this line can be deleted
Do While lRows < LastRow
Set rng = .Range(.Cells(lRows, col), .Cells(lRows + lLimit, col)) _
.Cells.SpecialCells(xlCellTypeBlanks)
rng.FormulaR1C1 = "=R[-1]C"
lRows = lRows + lLimit
Loop
Else
Set rng = .Range(.Cells(2, col), .Cells(LastRow, col)) _
.Cells.SpecialCells(xlCellTypeBlanks)
rng.FormulaR1C1 = "=R[-1]C"
End If
'replace formulas with values
With .Cells(1, col).EntireColumn
.Value = .Value
End With
End With
Last edited by a moderator: