+ Reply to Thread
Results 1 to 3 of 3

how do i use array of values for dim statement

  1. #1
    Registered User
    Join Date
    02-15-2006
    Posts
    13

    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.


    Please Login or Register  to view this content.

  2. #2
    Tom Ogilvy
    Guest

    Re: 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" <[email protected]> wrote in
    message news:[email protected]...
    >
    > 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. #3
    Registered User
    Join Date
    02-15-2006
    Posts
    13

    rethink logic

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

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1