Link to home
Start Free TrialLog in
Avatar of RWayneH
RWayneHFlag for United States of America

asked on

Copy a formula in A2 down column.

What is the VBA code to copy a formula down a column (is case A) starting at A2, and copying it down as long as there is a value in the cell to its right?  Then after that Copy>SpecialPaste>Values and number formats, so the formula is gone?

Assuming it starts with A2 being the active cell.

Please advise and thanks. -R-
ASKER CERTIFIED SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
RWH,

You're likely going to get a few methods of doing the same. Here's mine:
 With Range("A2")
  If Len(.Offset(0, 1).Value) > 0 And Len(.Offset(1, 1).Value) > 0 Then
   .Copy .Resize(.Offset(0, 1).End(xlDown).Row - .Row + 1, 1)
  .Resize(.Offset(0, 1).End(xlDown).Row - .Row + 1, 1).Value = .Resize(.Offset(0, 1).End(xlDown).Row - .Row + 1, 1).Value
  End If
 End With

Open in new window

Matt
Avatar of RWayneH

ASKER

EXCELent!!  -R-
EXCELent!!  -R-
:D

By the way, if this macro might ever be run when there is only one row of data in the column next to it, it will fill the formula down through every row in the sheet (1m+). If that is even a possibility, you may want to add something to check for that. If it is only run manually, and you wouldn't do it with only one row, then there's no need.