+ Reply to Thread
Results 1 to 4 of 4

Nested Case Statements that Return Values back onto Excel

  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?

    ________________

    Please Login or Register  to view this content.
    _____________

    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.

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Nested Case Statements that Return Values back onto Excel

    Can someone give me pointers on my code snippet?
    Yeah, delete it. Extremely flawed.

    Submit an example workbook which clearly demonstrates what you are trying to accomplish.

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

    Re: Nested Case Statements that Return Values back onto Excel

    I started from scratch and got my code working the way I want for a specific line. How can I "generalize" my code so that it runs until there are no more dates to check (column c)? Should I use an If statement? Furthermore, how should I change my code so that results pull in the first empty column?
    Attached Files Attached Files

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

    Re: Nested Case Statements that Return Values back onto Excel

    Here's the code:

    Option Explicit

    Private Sub Test_Click()

    Select Case Range("C7").Value

    Case "39814" To "40178" ‘converted dates to integers
    If Range("D7").Value = "AK" Then
    Range("AC7").Value = "1000"
    If Range("D7").Value = "CA" Then
    Range("AC7").Value = "4000"
    Else
    Range("AC7").Value = "600"
    End If

    Case “40179” To “40543”
    If Range("D1") = "MN" Then
    Range("AC1").Value = 500
    Else
    Range("AC1").Value = 300
    End If

    Case “40544” To “40908”
    If Range("D1") = "AZ" Then
    Range("AC1").Value = 5300
    Else
    Range("AC1").Value = 5000
    End If

    End Select

    End Sub

+ Reply to Thread

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