VBA Code for Message Box

AmandaP

New Member
Joined
Feb 15, 2018
Messages
3
Hi,

I have a workbook where they will be either a YES or NO Value in columns E, F or G. There will mostly be all NO values, but if there is a YES, i would like a message box to pop up and say "There is a negative fund, investment, or source!".

This is what i'm using now, but the message box is popping up even when there are no YES values present. Any help is much appreciated! I am kind of new to this and have been self taught so far. Thank you!

If ("E4:G3000") = "No" Then
Exit Sub
Else
MsgBox "There is a negative fund, investment, or source!", vbOKOnly
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Code:
For Each cell in Range("E4:G3000")
    If cell.Value = "No" Then
        [COLOR=#333333]MsgBox "There is a negative fund, investment, or source!", vbOKOnly[/COLOR]
        Exit Sub 'stop loop once you find one or else you get a messagebox for every cell with "No"
    End If
Next cell

you need to loop through the range or you can use the Find function... if it returns a range then it means it found the value https://msdn.microsoft.com/en-us/vba/excel-vba/articles/range-find-method-excel
 
Last edited:
Upvote 0
Hi & welcome to MrExcel
How about
Code:
Sub chk()
If WorksheetFunction.CountIf(Range("E4:G3000"), "Yes") > 0 Then MsgBox "There is a negative fund, investment, or source!"
End Sub
 
Last edited:
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,213,546
Messages
6,114,251
Members
448,556
Latest member
peterhess2002

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