stop running macro under conditions

whitoulias

Board Regular
Joined
Jun 22, 2012
Messages
146
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
 

Some videos you may like

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

puru.sve

Active Member
Joined
Apr 29, 2010
Messages
292
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
 

lancerj017

Active Member
Joined
Jan 25, 2012
Messages
318
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
 

Watch MrExcel Video

Forum statistics

Threads
1,122,514
Messages
5,596,612
Members
414,080
Latest member
penguin23

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
Top