Search a column find a value and create a message box

ckmacaus

New Member
Joined
Feb 14, 2019
Messages
1
Good evening, I have a question that I am sure will be simple for many; I was provided this to search a sheet in excel and find a value less than zero and create a msgbox.

Private Sub Worksheet_Calculate()
If Me.Range("$K$14").Value<0 Then_ MsgBox "Value can not be negative"
End Sub

This works fine for cell K14 but I want to apply it to all cells K14 to K54 on the sheet. Can you suggest anything? I have tried a number of things and searched for answers but I can not find the right fix.

Thank you for any suggestions in advance.
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Good evening, I have a question that I am sure will be simple for many; I was provided this to search a sheet in excel and find a value less than zero and create a msgbox.

Private Sub Worksheet_Calculate()
If Me.Range("$K$14").Value<0 Then_ MsgBox "Value can not be negative"
End Sub

This works fine for cell K14 but I want to apply it to all cells K14 to K54 on the sheet. Can you suggest anything? I have tried a number of things and searched for answers but I can not find the right fix.
I think I would simply turn the negative cells within that range red using conditional formatting instead.
 
Upvote 0
If you want to check it with macro and in the first negative cell you find stop macro

Code:
Private Sub Worksheet_Calculate()
    For Each wCell In Range("G14:K54")
        If wCell.Value < 0 Then
            MsgBox "Value can not be negative. Cell : " & wCell.Address
            Exit Sub
        End If
    Next
End Sub

Or if you want all the negative cells in a single message

Code:
Private Sub Worksheet_Calculate()
    For Each wcell In Range("G14:K54")
        If wcell.Value < 0 Then
            cad = cad & wcell.Address & ", "
        End If
    Next
    If cad <> "" Then
        MsgBox "Value can not be negative. Cell : " & cad
    End If
End Sub

Or with a simple cell format: Format Cell / Custom / Type:


#, ## 0.00; [Red] - #, ## 0.00
 
Upvote 0

Forum statistics

Threads
1,214,823
Messages
6,121,779
Members
449,049
Latest member
greyangel23

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