Thread: Autofill Macro.
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Gord Dibben Gord Dibben is offline
external usenet poster
 
Posts: 22,906
Default Autofill Macro.

You don't need a macro to do this.

Select the column and F5SpecialBlanksOK

Enter an = sign in active cell and point or arrow to cell above.

CTRL + ENTER to fill.

Copy and Paste SpecialValuesOKEsc.

But here is a macro if you choose.

Sub Fill_Blanks()
'by Dave Peterson 2004-01-06
'fill blank cells in column with value above
Dim wks As Worksheet
Dim rng As Range
Dim LastRow As Long
Dim col As Long

Set wks = ActiveSheet
With wks
col = ActiveCell.Column
'or
'col = .range("b1").column

Set rng = .UsedRange 'try to reset the lastcell
LastRow = .Cells.SpecialCells(xlCellTypeLastCell).Row
Set rng = Nothing
On Error Resume Next
Set rng = .Range(.Cells(2, col), .Cells(LastRow, col)) _
.Cells.SpecialCells(xlCellTypeBlanks)
On Error GoTo 0

If rng Is Nothing Then
MsgBox "No blanks found"
Exit Sub
Else
rng.NumberFormat = "General"
rng.FormulaR1C1 = "=R[-1]C"
End If

'replace formulas with values
With .Cells(1, col).EntireColumn
.Value = .Value
End With

End With

End Sub


Gord Dibben MS Excel MVP

On Mon, 29 Oct 2007 15:13:38 -0700, Dave A wrote:

Hi all,

trying to write a macro to do the following.

I have a column dates and blanks cells in between;

Oct 05


Nov 05


Dec05

I would like a macro to autofill down until the next non blank cell is
found and then repeat the autofill with the new cell until the end of
the column ie final result.
Oct05
Oct05
Oct05
Nov05
Nov05
Nov05
Nov05
Dec05

Thanks in advance
Dave