Combo Box VB code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tallie
    New Member
    • Mar 2008
    • 1

    Combo Box VB code

    I am fairly new to visual basic and I am using Excel.

    I am trying to create a calculator for donation tax credits. So what is supposed to happen is when a province is selected, the number of shares (found in cell E25) should be multiplied by a factor and the answer should be displayed in cell E29. However this is not working for me. Can someone please give me a hand?

    Private Sub ComboBox1_Click ()
    With ComboBox1
    .AddItem "BC"
    .AddItem "Alberta"
    .AddItem "Saskatchew an"
    .AddItem "Manitoba"
    .AddItem "Ontario"
    .AddItem "Quebec"
    .AddItem "New Brunswick"
    .AddItem "Nova Scotia"
    .AddItem "NFLD & Labrador"
    .AddItem "PEI"
    .AddItem "Yukon"
    .AddItem "NWT"
    .AddItem "Nunavut"
    End With

    If this.ComboBox1. selectedindex = "BC" Then
    Range(E29) = Range(E25) * 0.437
    If this.ComboBox1. selectedindex = "Alberta" Then
    Range(E29) = Range(E25) * 0.5
    If this.ComboBox1. selectedindex = "Saskatchew an" Then
    Range(E29) = Range(E25) * 0.44
    If this.ComboBox1. selectedindex = "Manitoba" Then
    Range(E29) = Range(E25) * 0.464
    If this.ComboBox1. selectedindex = "Ontario" Then
    Range(E29) = Range(E25) * 0.464
    If this.ComboBox1. selectedindex = "Quebec" Then
    Range(E29) = Range(E25) * 0.482
    If this.ComboBox1. selectedindex = "New Brunswick" Then
    Range(E29) = Range(E25) * 0.468
    If this.ComboBox1. selectedindex = "Nova Scotia" Then
    Range(E29) = Range(E25) * 0.483
    If this.ComboBox1. selectedindex = "NFLD & Labrador" Then
    Range(E29) = Range(E25) * 0.486
    If this.ComboBox1. selectedindex = "PEI" Then
    Range(E29) = Range(E25) * 0.474
    If this.ComboBox1. selectedindex = "Yukon" Then
    Range(E29) = Range(E25) * 0.424
    If this.ComboBox1. selectedindex = "NWT" Then
    Range(E29) = Range(E25) * 0.431
    If this.ComboBox1. selectedindex = "Nunavut" Then
    Range(E29) = Range(E25) * 0.405
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If


    End Sub
    Last edited by tallie; Mar 17 '08, 04:20 PM. Reason: didn't say what platform I am using
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    Why using Nested If ?

    If the first condition is false control will not test other conditions.

    check using

    If condition1 then
    ..........
    elseif condition2 then
    ....
    ..........
    end if

    Comment

    Working...