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
 

Some videos you may like

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Try like this

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

Mike Blackman

Well-known Member
Joined
Jun 8, 2007
Messages
2,494
Like this?

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

Watch MrExcel Video

Forum statistics

Threads
1,109,425
Messages
5,528,687
Members
409,830
Latest member
KT50

This Week's Hot Topics

  • Change military grades into rank
    Afternoon all Need help with formula that will change military rank (i.e. 1, 2, 3 into Amn, A1C, SrA). Running IF formula that does not work...
  • VBA COUNTIF SOLUTION
    Hi The following are the errors spread across the several columns from E to Q ie. 13 columns across several sheets with more than 500 rows per...
  • INSERT ROW WITH SPECIFIS TEXT IN A COLUMN
    Hi All! How can identify that that the row to be inserted has to be inserted before 1st row with specific text in column F. If I record the...
  • Auto-Create a monthly Sign in sheet for preschool students
    The image below is what each page looks like. Above is space for the "Child Name" "Month" "Class" School days are obviously Monday-Friday but...
  • VBA vlookup multiple results
    Hi folks, Hopefully someone out there can help. I have a list to vlookup which works (ish). the lookup only picks up the first instance of the...
  • Extract values for earliest/latest times
    I am trying to put together a formula to get the earliest start time, the latest end time from column A for each person in Column B-F without the...
Top