how to exit/quit macro after a if statement?

welkin

New Member
Joined
Jun 15, 2008
Messages
7
I have below if statement and if this is true, i want to exit the macro after executing without going to the rest of the codes after end if.


If Range("B2") = "abc" Then

Range("A2").Value = "abc" & Format(today, "ddmmyy")
Range("B2:E2").Select
Selection.ClearContents

End If

is there a way to skip to end sub()? or should I replace the if statement with something else?

Many Tks in advance.
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
welkin

There may be a more "elegant" way to deal with this. What else does your code do if B2 is not equal to "abc"?

If your code is not too long, perhaps you could post it here? If so, please use code tags around your code to make it easier to read. [ code ] (without spaces) before your code and [ /code ] (without spaces) after your code.
 
Upvote 0
Thanks both.

Exit sub works perfectly.

I tired exit previously but i missed out the "sub" and hence it did not work.
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,592
Members
449,089
Latest member
Motoracer88

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