Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Like Operator

I'm trying to stop a procedure if an excel cell contains a space.
Example; cell contains <M T91490

I've tried an if statement, but it's not returning the result I'm looking
for.

If activecell.value like " " then
msgbox "Check cell contents"
exit sub
end if

I've also tried this;

If activecell.text like " " then
msgbox "Check cell contents"
exit sub
end if




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default Like Operator

Try: Like "* *"

--
Jim Rech
Excel MVP
"Donald" wrote in message
news:wQGDc.22019$Lh.4105@okepread01...
I'm trying to stop a procedure if an excel cell contains a space.
Example; cell contains <M T91490

I've tried an if statement, but it's not returning the result I'm looking
for.

If activecell.value like " " then
msgbox "Check cell contents"
exit sub
end if

I've also tried this;

If activecell.text like " " then
msgbox "Check cell contents"
exit sub
end if






  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Like Operator

If instr(activecell.text," ") then
msgbox "Check cell contents"
exit sub
end if


--
Regards,
Tom Ogilvy

"Donald" wrote in message
news:wQGDc.22019$Lh.4105@okepread01...
I'm trying to stop a procedure if an excel cell contains a space.
Example; cell contains <M T91490

I've tried an if statement, but it's not returning the result I'm looking
for.

If activecell.value like " " then
msgbox "Check cell contents"
exit sub
end if

I've also tried this;

If activecell.text like " " then
msgbox "Check cell contents"
exit sub
end if






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Like Operator

Thanks to both, appears as though both methods work. Would one method have
any advantage over the other?

--
Donald
"Tom Ogilvy" wrote in message
...
If instr(activecell.text," ") then
msgbox "Check cell contents"
exit sub
end if


--
Regards,
Tom Ogilvy

"Donald" wrote in message
news:wQGDc.22019$Lh.4105@okepread01...
I'm trying to stop a procedure if an excel cell contains a space.
Example; cell contains <M T91490

I've tried an if statement, but it's not returning the result I'm

looking
for.

If activecell.value like " " then
msgbox "Check cell contents"
exit sub
end if

I've also tried this;

If activecell.text like " " then
msgbox "Check cell contents"
exit sub
end if








  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Like Operator

I haven't done any timing tests to see if one is faster than the other, but
I don't think either would have an observable difference.

--
Regards,
Tom Ogilvy

"Donald" wrote in message
news:E0JDc.22030$Lh.2080@okepread01...
Thanks to both, appears as though both methods work. Would one method have
any advantage over the other?

--
Donald
"Tom Ogilvy" wrote in message
...
If instr(activecell.text," ") then
msgbox "Check cell contents"
exit sub
end if


--
Regards,
Tom Ogilvy

"Donald" wrote in message
news:wQGDc.22019$Lh.4105@okepread01...
I'm trying to stop a procedure if an excel cell contains a space.
Example; cell contains <M T91490

I've tried an if statement, but it's not returning the result I'm

looking
for.

If activecell.value like " " then
msgbox "Check cell contents"
exit sub
end if

I've also tried this;

If activecell.text like " " then
msgbox "Check cell contents"
exit sub
end if












  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 733
Default Like Operator

"Tom Ogilvy" wrote...
If instr(activecell.text," ") then
msgbox "Check cell contents"
exit sub
end if


Why .Text rather than .Value? Unexpected things could happen in some Date
and mixed Date/Time number formats. Suppose it's up to the OP whether dates
appearing like '28 Jun 2004' but stored as 38166 would be considered
stopping criteria.

InStr(x, " ") is likely to be faster than x Like "* *", but a single
instance of either would take negligible time.


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Like Operator

I assume the OP can determine what is appropriate to his or her situation.

ActiveCell.Text appeared most appropriate to me in this instance. Dates
weren't an issue in the question and it wasn't offered as a turnkey solution
to all such tests. As long as we are going to imagine any conceivable
situation, if in regional settings the user set MM dd, yyyy as the short
date format, then using value would be problematic as well:

From the immediate window:
? activeCell.Value
Jun 24, 2004
? Instr(activecell.Value," ")
4

So value2 would need to be used in that case.

Thanks for your interest.

--
Regards,
Tom Ogilvy




"Harlan Grove" wrote in message
...
"Tom Ogilvy" wrote...
If instr(activecell.text," ") then
msgbox "Check cell contents"
exit sub
end if


Why .Text rather than .Value? Unexpected things could happen in some Date
and mixed Date/Time number formats. Suppose it's up to the OP whether

dates
appearing like '28 Jun 2004' but stored as 38166 would be considered
stopping criteria.

InStr(x, " ") is likely to be faster than x Like "* *", but a single
instance of either would take negligible time.




  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default Like Operator

"Tom Ogilvy" wrote...
I assume the OP can determine what is appropriate to his or her situation.


They always have to anyway.

ActiveCell.Text appeared most appropriate to me in this instance. Dates
weren't an issue in the question and it wasn't offered as a turnkey solution
to all such tests. As long as we are going to imagine any conceivable
situation, if in regional settings the user set MM dd, yyyy as the short
date format, then using value would be problematic as well:

...
So value2 would need to be used in that case.


In the sense that the OP's single example, "cell contains <M T91490" made it
appear the cells would contain text, then there would have been little
difference between .Text and .Value. I fully agree that .Value2 would have made
more sense than your original suggestion of .Text.

--
To top-post is human, to bottom-post and snip is sublime.
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Like Operator

Thanks to all. In my particular scenario, the cell will/should always
contain an alphameric entry (text if you will).

--
Donald
"Harlan Grove" wrote in message
...
"Tom Ogilvy" wrote...
I assume the OP can determine what is appropriate to his or her

situation.

They always have to anyway.

ActiveCell.Text appeared most appropriate to me in this instance. Dates
weren't an issue in the question and it wasn't offered as a turnkey

solution
to all such tests. As long as we are going to imagine any conceivable
situation, if in regional settings the user set MM dd, yyyy as the short
date format, then using value would be problematic as well:

..
So value2 would need to be used in that case.


In the sense that the OP's single example, "cell contains <M T91490" made

it
appear the cells would contain text, then there would have been little
difference between .Text and .Value. I fully agree that .Value2 would have

made
more sense than your original suggestion of .Text.

--
To top-post is human, to bottom-post and snip is sublime.



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
about & operator [email protected] Excel Discussion (Misc queries) 2 December 12th 08 04:44 PM
Operator for Contains Leanne M (Aussie) Excel Worksheet Functions 2 October 21st 08 11:01 AM
Operator kittycris Excel Worksheet Functions 3 January 11th 07 01:36 AM
IN operator Suzanne Excel Worksheet Functions 4 May 10th 06 06:28 PM
XOR Operator - How? Randy Brown Excel Discussion (Misc queries) 3 April 8th 06 09:47 PM


All times are GMT +1. The time now is 04:34 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"