Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default how do i use array of values for dim statement


How do I simplify the code below instead of putting all of the different
strings together? I want it to say if MyStr does not equal 1 or 4 or 7
or 10 then message box appears. I'm doing it the long way...I know
there's a shorter way.



Code:
--------------------
Dim AnyString, MyStr
AnyString = Range("assignment")
MyStr = Right(AnyString, 1)
If MyStr = 2 Then
MsgBox ("Assignment number must end with 1,4,7,10,13")
Exit Sub
End If
If MyStr = 3 Then
MsgBox ("Assignment number must end with 1,4,7,10,13")
Exit Sub
End If
If MyStr = 5 Then
MsgBox ("Assignment number must end with 1,4,7,10,13")
Exit Sub
End If
If MyStr = 6 Then
MsgBox ("Assignment number must end with 1,4,7,10,13")
Exit Sub
End If
If MyStr = 8 Then
MsgBox ("Assignment number must end with 1,4,7,10,13")
Exit Sub
End If
If MyStr = 9 Then
MsgBox ("Assignment number must end with 1,4,7,10,13")
Exit Sub
End If
If MyStr = 11 Then
MsgBox ("Assignment number must end with 1,4,7,10,13")
Exit Sub
End If
If MyStr = 12 Then
MsgBox ("Assignment number must end with 1,4,7,10,13")
Exit Sub
End If
--------------------


--
vbidiot
------------------------------------------------------------------------
vbidiot's Profile: http://www.excelforum.com/member.php...o&userid=31582
View this thread: http://www.excelforum.com/showthread...hreadid=518085

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default how do i use array of values for dim statement

For single digits:

if mystr like "[235689]" then



However, you can't get the single right most character and check if it
equals "10", "11", "12", or "13"

Also, if the single right most character is 3, why couldn't it end in 13.
You have to differentiate.

Think you need to rethink your logic

--
Regards,
Tom Ogilvy




"vbidiot" wrote in
message ...

How do I simplify the code below instead of putting all of the different
strings together? I want it to say if MyStr does not equal 1 or 4 or 7
or 10 then message box appears. I'm doing it the long way...I know
there's a shorter way.



Code:
--------------------
Dim AnyString, MyStr
AnyString = Range("assignment")
MyStr = Right(AnyString, 1)
If MyStr = 2 Then
MsgBox ("Assignment number must end with 1,4,7,10,13")
Exit Sub
End If
If MyStr = 3 Then
MsgBox ("Assignment number must end with 1,4,7,10,13")
Exit Sub
End If
If MyStr = 5 Then
MsgBox ("Assignment number must end with 1,4,7,10,13")
Exit Sub
End If
If MyStr = 6 Then
MsgBox ("Assignment number must end with 1,4,7,10,13")
Exit Sub
End If
If MyStr = 8 Then
MsgBox ("Assignment number must end with 1,4,7,10,13")
Exit Sub
End If
If MyStr = 9 Then
MsgBox ("Assignment number must end with 1,4,7,10,13")
Exit Sub
End If
If MyStr = 11 Then
MsgBox ("Assignment number must end with 1,4,7,10,13")
Exit Sub
End If
If MyStr = 12 Then
MsgBox ("Assignment number must end with 1,4,7,10,13")
Exit Sub
End If
--------------------


--
vbidiot
------------------------------------------------------------------------
vbidiot's Profile:

http://www.excelforum.com/member.php...o&userid=31582
View this thread: http://www.excelforum.com/showthread...hreadid=518085



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default how do i use array of values for dim statement


You're right...I didn't even think about I included two digits as well
as single digits. Thanks!


--
vbidiot
------------------------------------------------------------------------
vbidiot's Profile: http://www.excelforum.com/member.php...o&userid=31582
View this thread: http://www.excelforum.com/showthread...hreadid=518085

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 Statement / Array JEFF Excel Worksheet Functions 6 October 29th 08 03:28 AM
Array: Counting multiple values within array Trilux_nogo Excel Worksheet Functions 4 April 16th 07 03:12 AM
Use array to return array of values Brad Excel Worksheet Functions 2 March 30th 06 05:58 PM
Range array need it in one statement? Simon Lloyd[_613_] Excel Programming 0 November 24th 04 02:14 AM
Convert values in a variant array to integer values Graham McNeill Excel Programming 1 November 13th 04 12:47 AM


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