Results 1 to 4 of 4

Problems with a case...select function

Threaded View

abbysdad Problems with a case...select... 12-25-2009, 02:07 PM
JBeaucaire Re: Problems with a... 12-25-2009, 02:33 PM
abbysdad Re: Problems with a... 12-25-2009, 02:59 PM
JBeaucaire Re: Problems with a... 12-26-2009, 04:25 PM
  1. #1
    Registered User
    Join Date
    12-25-2009
    Location
    Pennsylvania
    MS-Off Ver
    Excel 2003
    Posts
    2

    Problems with a case...select function

    Hi,

    I'm writing some macros for use in a game that I play. Apparently I've neglected something or there is a dumb mistake in my code. I'd appreciate any help in debugging it. I use Excel 2003 in WinXP (latest service packs and updates).

    The intent of the macro is to take a string as input (dettype) to a case... select series. The dettype input is from a drop down list that is passed onto the current worksheet from another page and then the output of the resulting number of units for that option (grnnum) is supposed to be displayed in the cell.

    As an example of the intended code implementation and desired results, if I enter a value of Cavalry from cell A1 into the function 'greens' in cell A2 I want to see a value of 2 returned (grnnum = 2) in cell A2.

    The code that I have so far returns a value of zero (0), regardless of the value of dettype.

    I'm not sure why.

    Thanks in advance for any help!

    Merry Christmas,

    Chris

    Public Function greens(dettype As String) As Variant
    Dim grnnum As Variant
    '------------------------
    'Logic case selections for DetType results
        If dettype = " " Then
            grnnum = "Select a Detachment Type"
        Else
            Select Case dettype
    '--------------------
                Case Is = "Cavalry"
                    grnnum = 2
                Case Is = "Command"
                    grnnum = 0
                Case Is = "Experimental"
                    grnnum = 2
                Case Is = "Infantry"
                    grnnum = 3
                Case Is = "Motorized Infantry"
                    grnnum = 3
                Case Is = "Occult"
                    grnnum = 2
                Case Is = "Reconnaisance"
                    grnnum = 2
                Case Is = "Support"
                    grnnum = 2
                Case Is = "Tank"
                    grnnum = 2
                Case Is = "Veteran"
                    grnnum = 0
                Case Else
                    grnnum = 0
    '--------------------
                End Select
        End If
    End Function
    Last edited by abbysdad; 12-25-2009 at 02:55 PM.

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