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
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
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
 
Upvote 0

Forum statistics

Threads
1,215,633
Messages
6,125,922
Members
449,274
Latest member
mrcsbenson

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top