error while running a macro

navyaa

Board Regular
Joined
Jul 7, 2002
Messages
223
I am running a macro where i have specified a loop and this line of code is a part of it:

If ActiveCell.Value >= 30 Then

This checks the cell the cursor is positioned at to check is value is >30 . My problem is that the cell being checked for >30 has a number(#NUM!) error and when this happens the macro stops executing and says "mismatch".

I was wondering if there was some way in which i could just specify in the condition that when the macro encounters (#NUM!) instead of a number to check if >30 it should ignore it and keep running?

Any suggestions?

Thank you,
Navya
 

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.
Hi Navya,

See if you can amend this to suit your needs:

<pre>Sub number_test()

If IsNumeric(ActiveCell.Value) Then
If ActiveCell.Value >= 30 Then
MsgBox "Its not < 30 - I'll run my routine"
Else
MsgBox "Its < 30 - no good this time!"
Exit Sub
End If
Else
MsgBox "Its not a number - I'm going to quit!"
Exit Sub
End If

End Sub</pre>

HTH
 
Upvote 0

Forum statistics

Threads
1,226,727
Messages
6,192,686
Members
453,746
Latest member
Bruce at Pubdarts

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