Fill down only cells with Formulas VBA

D

Dennis

Using Excel 2003

In the VBA code below, how do I change the code to Fill Down ONLY when
Offset(-1,0) is a true formula. i.e. =A1+B1

In this case, I do not want numbers or dates to Fill Down.

Sub QuickFill()
Dim myRange As Range, myCell As Range
Set myRange = Application.InputBox("Select the cells", _
"Make Your Selection", Type:=8)
For Each myCell In myRange
myCell.Formula = myCell.Offset(-1, 0).Value
Next
End Sub


TIA Dennis
 
D

Dave Peterson

One way is to just check:

Sub QuickFill()
Dim myRange As Range, myCell As Range
Set myRange = Application.InputBox("Select the cells", _
"Make Your Selection", Type:=8)
For Each myCell In myRange
if mycell.offset(-1,0).hasformula then
myCell.Formula = myCell.Offset(-1, 0).Value
end if
Next
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top