Option Explicit
Sub AutoFillMacro()
Dim LastRow As Long
Dim FillRange As Range
Dim DataRange As Range
Dim Prompt As String
Dim Title As String
Prompt = "Select the column that contains your data."
Title = "Data Range Input"
On Error Resume Next
Set DataRange = Application.InputBox(Prompt, Title, _
ActiveCell.EntireColumn.Address, , , , , 8)
On Error GoTo 0
If DataRange Is Nothing Then
Exit Sub
End If
Prompt = "Select the cell with the formula to be used for the fill."
Title = "Fill Range Input"
On Error Resume Next
Set FillRange = Application.InputBox(Prompt, Title, _
ActiveCell.Address, , , , , 8)
On Error GoTo 0
If FillRange Is Nothing Then
Exit Sub
End If
Set FillRange = FillRange(1, 1)
LastRow = Cells(65536, DataRange.Column).End(xlUp).Row
If LastRow > FillRange.Row Then
FillRange.AutoFill Range(FillRange.Address & ":" & _
Cells(LastRow, FillRange.Column).Address), xlFillDefault
End If
End Sub
|