IF statement in macro

JRS

New Member
Joined
Mar 10, 2011
Messages
44
I'm trying to get an IF statement to work but not sure where I'm going wrong.
I have got a selection copied (in a macro) from sheet1, and the IF statement needs to do something along the lines of.

IF(A2 in sheet2 is empty, than paste selection in A2 of sheet2, otherwise paste in A10 of sheet2)

I started with:

IF(A2=0, (Destination:=Sheet2.Range("A2")), (Destination:=Sheet2.Range("A10"))

But it keeps on throwing up a compile error with the comma just after A2=0
 

Some videos you may like

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

JamesW

Well-known Member
Joined
Oct 30, 2009
Messages
1,197
Hi there,

Try:

Code:
    With Sheets("Sheet2")
        If .Range("A2").Value = "" Then
            .Paste Destination:=.Range("A2")
        Else
            .Paste Destination:=.Range("A10")
        End If
    End With
 

Watch MrExcel Video

Forum statistics

Threads
1,108,492
Messages
5,523,262
Members
409,506
Latest member
reneekeane

This Week's Hot Topics

Top