user1283776
user1283776

Reputation: 21764

Using VBA, copy all formulas from one sheet to another and nothing else?

I want to copy all formulas from one sheet to another using VBA. I don't want to copy anything else than the formulas. What is a good way to do this?

To explain with an example, if the source sheet contains:

formula value   value
blank   formula value
blank   blank   formula

and the target sheet contains:

1   2   3
4   5   6
7   8   9

I want the target sheet to get the values:

formula 2   3
4   formula 6
7   8   formula

Upvotes: 0

Views: 2564

Answers (1)

Gary's Student
Gary's Student

Reputation: 96753

How about:

Sub dural()
    Dim r As Range, ady As String
    For Each r In Sheets("Sheet1").Cells.SpecialCells(xlCellTypeFormulas)
        ady = r.Address
        r.Copy Sheets("Sheet2").Range(ady)
    Next
End Sub

Upvotes: 1

Related Questions