Simple VBA Code not working

drhatmrexcel

Board Regular
Joined
Oct 30, 2009
Messages
69
Simple Code does not work


If Range("B7") = "1" Then
End If

When there is a 1 in cell B7 the code falls through and executes the remaining code whereas it should stop immediately.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Simple Code does not work


If Range("B7") = "1" Then
End If

When there is a 1 in cell B7 the code falls through and executes the remaining code whereas it should stop immediately.
Try removing those red quotes which convert the number 1 into the string "1"
 
Upvote 0
I'd like to see a bit more of the context of your code but I'd that you consider inserting:
Exit If
within the IF.

And yes, I did miss the quotes, so depending upon your scenario you may have another thought to consider.
 
Last edited:
Upvote 0
Simple Code does not work


If Range("B7") = "1" Then
End If

When there is a 1 in cell B7 the code falls through and executes the remaining code whereas it should stop immediately.
Depends on what's after the End If. If you want the code to stop try:

If Range("B7") =1 Then
Exit Sub
End If
 
Upvote 0
OK adding the Exit Sub before the End If did the trick
Now I will see if it works in my main spreadsheet.
Been suffering why a simple IF statement was not working.
Thank You JoeMo and all others on the site.
 
Upvote 0
OK adding the Exit Sub before the End If did the trick
Now I will see if it works in my main spreadsheet.
Been suffering why a simple IF statement was not working.
Thank You JoeMo and all others on the site.
You are welcome - thanks for the reply.
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,270
Members
452,628
Latest member
dd2

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