View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein \(MVP - VB\) Rick Rothstein \(MVP - VB\) is offline
external usenet poster
 
Posts: 2,202
Default Filldown top cell to last row with data in adjacent col

Jim, thanks. Afraid I can't access that link in office. It's blocked
(darn!).
Will check it up back home.


Sorry. Use this one. I just removed the msgbox I was using to help me
while writing the code :)

Sub filldown()

Dim Lrow As Long
Dim Col As Variant
Dim i As Variant
Dim lCol As Variant
With ActiveCell
i = .Address
End With
lCol = Mid(ActiveCell.Offset(0, -1).Columns.Address, 2,
WorksheetFunction.Find("$", _
ActiveCell.Offset(0, -1).Columns.Address, 2) - 2)
Col = Mid(ActiveCell.Columns.Address, 2,
WorksheetFunction.Find("$", _
ActiveCell.Columns.Address, 2) - 2)
Lrow = Range(lCol & Rows.Count).End(xlUp).Row
ActiveCell.FormulaR1C1 = "Your Formula"
ActiveCell.Select
Selection.AutoFill Destination:=Range(i & ":" & Col & Lrow),
Type:=xlFillDefault
End Sub


I think we can shorten that a bit...

Sub FillDown()
ActiveCell.Formula = "Your Formula"
ActiveSheet.Range(ActiveCell.Address & ":" & Cells(Rows.Count, _
ActiveCell.Offset(0, -1).Column).End(xlUp). _
Offset(0, 1).Address).FillDown
End Sub

If the formula already exist in the active cell, then the first line of code
can be omitted (that was the approach JLGWhiz appears to have taken).

Rick