Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Sam Sam is offline
external usenet poster
 
Posts: 699
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 523
Default 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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
code to 'put' calc displayed in message box in cells shaz0503 Excel Discussion (Misc queries) 5 February 6th 09 05:35 PM
macro runs fine but error message is displayed already Excel Programming 4 November 11th 08 07:26 PM
how can I have a message displayed when a spreedsheet is opened ? dleus Excel Discussion (Misc queries) 2 May 17th 08 05:09 PM
Display a form prior to workbook being displayed pkm Excel Programming 0 February 22nd 06 07:04 PM
No message box displayed Marc Excel Discussion (Misc queries) 1 January 7th 06 03:49 PM


All times are GMT +1. The time now is 10:32 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"