stop running macro under conditions

whitoulias

Board Regular
Joined
Jun 22, 2012
Messages
153
Good day to all

I would like to add a piece of code that it will stop running macro.

The condition is that if one ore more cells in range A1:A4 is empty then the macro will stop running

Any ideas?

Thank you
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Try this ..... Exit sub statement use for stopping macro



Code:
Sub Marco()
Dim rng As Range
For Each rng In Range("A1:A4")
    If rng Is Nothing Then    ' checking rng is blank or not 
    
        Exit Sub    ' it will stop macro if rng is blank 
        

    Else 

         'do your work here 

    End If
    
Next rng
End Sub
 
Upvote 0
or try this just put the code above your code
Rich (BB code):
sub test()
Dim myrange As Range
Set myrange = Range("A1:A4")
    If Application.WorksheetFunction.CountA(myrange) <> 4 Then Exit Sub

'your code
end sub
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,429
Members
448,961
Latest member
nzskater

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