Results 1 to 4 of 4

Nested Case Statements that Return Values back onto Excel

Threaded View

  1. #1
    Registered User
    Join Date
    03-25-2015
    Location
    Seattle, Washington
    MS-Off Ver
    2007
    Posts
    3

    Nested Case Statements that Return Values back onto Excel

    I'm new to VBA and am trying to write a macro that tells me insurance premiums for a given accident based on the the accident date and state.

    Ex.

    1/1/2009 to 12/31/2009 for AK = $1000, CA = $4000, and all other states = $600
    1/1/2010 to 12/31/2010 for MN = $500, all other states = $300
    1/1/2011 to 12/31/2010 for AZ = $5300, all other states = $5000

    I want to be able to push a button and have this information pull into a certain column.

    Can someone give me pointers on my code snippet?

    ________________

    Option Explicit
    
        'Pulls Date for Macro to Run
        Sub GetDate()
        Dim MyDate As Integer
        MyDate = Range("C:C").Value
        End Sub
    
        'Pulls State Info for Macro to Run
        Sub GetState()
        Dim MyState As String
        MyState = Range("D:D").Value
        End Sub
    
    Private Sub CommandButton21_Click() '<-This line pulls up with an error message
        
        Dim ws As Worksheet
        Set ws = Worksheets("Report 1")
        Set ws = ActiveSheet
        
        Select Case Date
       
               
        Case 1 / 1 / 2009 To 12 / 31 / 2009
    	If State = "AK" Then SIR = 1000 '<- This line pulls up as "Compile error: variable note defined
    		If State = "CA" Then SIR = 4000
            Else            
    	
    	SIR = 600
                
        Case 1 / 1 / 2010  To 1 / 31 / 2010
            If State = "MN" Then SIR = 500
            Else
                SIR = 300
                
        End Select
        
    End Sub
    _____________

    If nested case statements isn't the best way to go, please point me in the right direction.
    Thanks!
    Last edited by jeffreybrown; 03-25-2015 at 09:13 PM. Reason: Please use code tags...Thanks.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Nested Case statements... I broke it!
    By keithwins in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-15-2014, 01:38 PM
  2. Referencing range values for case statements.
    By jimmyex23 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-27-2013, 08:34 PM
  3. Alternative to multiple nested IF statements to SUM certain values
    By JTR616 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 09-24-2013, 06:23 PM
  4. [SOLVED] Nested IF statements to FIND text string and return set values.
    By stuartm4h in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-12-2013, 12:03 PM
  5. Using ComboBox values for case statements
    By dylcon in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 05-10-2013, 09:21 AM

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