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

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

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
 

Forum statistics

Threads
1,141,227
Messages
5,705,137
Members
421,380
Latest member
Nuwan Sanjeewa Aponso

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
Top