macro when run if any cells have minus vale in range give warning message?

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,194
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,

I'd like a macro that when run checks if any cells in range D21:BZ2500 has a negative value and if it does bring up a message box saying "Can't proceed with Negative Values"


suck again,

please help

Tony
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Try this:
Code:
Sub check_Range()
Dim c As Range
For Each c In Range("D21:BZ2500")
    If c.Value < 0 Then MsgBox "Can't proceed with Negative Values": Exit Sub
Next
End Sub
 
Upvote 0
And if you want to know which cell has a negative value try this script:

It will tell you what cell and highlight the cell in red.
But it stops after finding the first one like you said.

Code:
Sub check_Range()
Dim c As Range
For Each c In Range("D21:BZ2500")
    If c.Value < 0 Then
    
    c.Interior.Color = vbRed
    MsgBox "Can't proceed with Negative Values" & vbNewLine & "Cell  " & c.Address & "  has a negative value"
    Exit Sub
End If
Next
End Sub
 
Upvote 0
Hi Mate,
these are both excellent!
thank you so much I think I'll use the second one, but both great :)

Tony
 
Upvote 0

Forum statistics

Threads
1,213,535
Messages
6,114,198
Members
448,554
Latest member
Gleisner2

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