stop macro depending on cell value

dan3721

New Member
Joined
Dec 23, 2009
Messages
18
Hi

I am looking for the code that stops a macro depending on a cell value.

For instance is cell D4 contains the number 1 I want the macro to stop bring up a nessage box saying it has stopped and not carry on. If there is not a number 1 in cell D4 then i want it to continue with the rest of the macro.

Any idea?

Thanks

Dan
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Try like this

Code:
If Range("D4").Value = 1 Then
    MsgBox "Macro stopped"
    Exit Sub
End If
'
'rest of code
 
Upvote 0
Like this?

Code:
If Range("D4").Value = 1 Then
    MsgBox Prompt:="This Macro has stopped", _
           Buttons:=vbInformation
    Exit Sub
end if
 
Upvote 0

Forum statistics

Threads
1,215,461
Messages
6,124,958
Members
449,200
Latest member
indiansth

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