ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   HELP: Display a message when one of the names is displayed in a ra (https://www.excelbanter.com/excel-programming/437179-help-display-message-when-one-names-displayed-ra.html)

Sam

HELP: Display a message when one of the names is displayed in a ra
 
Hi All,

How can I display a message box if a range (B1:B10) has one of these values
(tom,ross,chad,sam,josh,jill) on a button click (DisplayMessage)

Here is what I have so far but I get a type mismatch error:

Sub DisplayMessage_Click()

If Worksheets("Sheet1").Range("B1:B10) = "tom" or "ross" or "chad" or "sam"
or "josh" or "jill") Then

MsgBox ("Name present")

End If

End sub

Thanks in advance


Sam Wilson

HELP: Display a message when one of the names is displayed in a ra
 
You need

with worksheets("Sheet1").range("B1")
if .value = "Sam" or .value = "Tom" ... or .value = "Jill" then
msgbox "Name present"
end if
end with

or if the cells B1 to B10 aren't merged then

dim rng as range, c as range
set rng = worksheets("Sheet1").range("B1:B10")
for each c in rng
with c
if .value = "Sam" or .value = "Tom" ... or .value = "Jill" then
msgbox "Name present"
end if
end with
next c

end with

"Sam" wrote:

Hi All,

How can I display a message box if a range (B1:B10) has one of these values
(tom,ross,chad,sam,josh,jill) on a button click (DisplayMessage)

Here is what I have so far but I get a type mismatch error:

Sub DisplayMessage_Click()

If Worksheets("Sheet1").Range("B1:B10) = "tom" or "ross" or "chad" or "sam"
or "josh" or "jill") Then

MsgBox ("Name present")

End If

End sub

Thanks in advance



All times are GMT +1. The time now is 07:10 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com