Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Sets of Characters in Excel VBA


Hi,

I want to compare a single character to see if it is one of severa
characters. eg 1 to 9. I thought VBA supported sets ?

ie Assuming MyString is 1 charcter in length, Instead of doing this:
If MyString = "1" or MyString = "2" or MyString = "3" etc..... The
...

Can I do:
If MyString = {1..9} Then ....
Excel VBA doesn't like the curly bracket, it spits any error.

Does anyone know how to compare of value to a set or list like this ?

Thanks in Advance for any help.
Craig

--
aussie_crai
-----------------------------------------------------------------------
aussie_craig's Profile: http://www.excelforum.com/member.php...fo&userid=1549
View this thread: http://www.excelforum.com/showthread.php?threadid=27071

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default Sets of Characters in Excel VBA

Here is an approach you could alter for your needs:

Sub test()
Dim MyString As String, bln As Boolean

MyString = "4"

Select Case MyString
Case "1", "3", "5", "7", "9": bln = True
Case Else: bln = False
End Select

If bln Then
MsgBox "1 to 9"
End If
End Sub


You could also change to:
Case 1 To 9: bln = True


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"aussie_craig" wrote in message
...

Hi,

I want to compare a single character to see if it is one of several
characters. eg 1 to 9. I thought VBA supported sets ?

ie Assuming MyString is 1 charcter in length, Instead of doing this:
If MyString = "1" or MyString = "2" or MyString = "3" etc..... Then
..

Can I do:
If MyString = {1..9} Then ....
Excel VBA doesn't like the curly bracket, it spits any error.

Does anyone know how to compare of value to a set or list like this ?

Thanks in Advance for any help.
Craig.


--
aussie_craig
------------------------------------------------------------------------
aussie_craig's Profile:
http://www.excelforum.com/member.php...o&userid=15491
View this thread: http://www.excelforum.com/showthread...hreadid=270714



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 968
Default Sets of Characters in Excel VBA

Hi Craig,

You can also use INSTR
strList="123456789"
if instr(strList,MyString)0 then

or LIKE
if MyString like "[1-9]" then


--
Charles
______________________
Decision Models
FastExcel 2.1 now available
www.DecisionModels.com
"aussie_craig" wrote in message
...

Hi,

I want to compare a single character to see if it is one of several
characters. eg 1 to 9. I thought VBA supported sets ?

ie Assuming MyString is 1 charcter in length, Instead of doing this:
If MyString = "1" or MyString = "2" or MyString = "3" etc..... Then
..

Can I do:
If MyString = {1..9} Then ....
Excel VBA doesn't like the curly bracket, it spits any error.

Does anyone know how to compare of value to a set or list like this ?

Thanks in Advance for any help.
Craig.


--
aussie_craig
------------------------------------------------------------------------
aussie_craig's Profile:
http://www.excelforum.com/member.php...o&userid=15491
View this thread: http://www.excelforum.com/showthread...hreadid=270714



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default Sets of Characters in Excel VBA

Hey cool!
That's like regular expressions. When did VBA get that?!

--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Charles Williams" wrote in message
...
Hi Craig,

You can also use INSTR
strList="123456789"
if instr(strList,MyString)0 then

or LIKE
if MyString like "[1-9]" then


--
Charles
______________________
Decision Models
FastExcel 2.1 now available
www.DecisionModels.com
"aussie_craig" wrote in
message ...

Hi,

I want to compare a single character to see if it is one of several
characters. eg 1 to 9. I thought VBA supported sets ?

ie Assuming MyString is 1 charcter in length, Instead of doing this:
If MyString = "1" or MyString = "2" or MyString = "3" etc..... Then
..

Can I do:
If MyString = {1..9} Then ....
Excel VBA doesn't like the curly bracket, it spits any error.

Does anyone know how to compare of value to a set or list like this ?

Thanks in Advance for any help.
Craig.


--
aussie_craig
------------------------------------------------------------------------
aussie_craig's Profile:
http://www.excelforum.com/member.php...o&userid=15491
View this thread:
http://www.excelforum.com/showthread...hreadid=270714





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 863
Default Sets of Characters in Excel VBA

Several versions ago <bg.

On Wed, 20 Oct 2004 20:37:49 +1300, "Rob van Gelder"
wrote:

Hey cool!
That's like regular expressions. When did VBA get that?!




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 968
Default Sets of Characters in Excel VBA

It was there in Excel Version 5 (I just checked)


"Myrna Larson" wrote in message
...
Several versions ago <bg.

On Wed, 20 Oct 2004 20:37:49 +1300, "Rob van Gelder"
wrote:

Hey cool!
That's like regular expressions. When did VBA get that?!




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
if, then, else with Excel 2007 icon sets bikierguy Excel Discussion (Misc queries) 1 January 2nd 09 01:53 AM
2 sets of =if strings in excel 2007 v1rt8 Excel Discussion (Misc queries) 1 September 9th 08 04:30 AM
Excel graph 3 sets of data. 2 sets as lines 1 as column? AndyN Charts and Charting in Excel 2 July 11th 08 01:18 PM
In Excel find characters when multiple characters exist w/i a cel teacher-deburg Excel Worksheet Functions 1 December 5th 05 10:22 PM
anyway to go with excel two sets of data rob Charts and Charting in Excel 2 September 15th 05 04:51 AM


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

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

About Us

"It's about Microsoft Excel"