I think I need some advice on forms, please.

cornflakegirl

Well-known Member
Joined
Nov 4, 2004
Messages
2,023
I need to calculate the profit impact of system downtime. The impact is dependent on a number of things, including the length of time, the purchasing channels affected and the products affected.

I want to produce a little spreadsheet that anyone can use that will generate the cost for any set of circumstances. So they need to be able to choose the channel - 1 or more of about 10, and the product - 1 or more of 5. There will be another couple of categories too, with maybe 5 options in each.

Each category option will have have a multiplication factor associated with it - if more than one option is selected, the factors will be summed.

I think I probably need checkboxes, but they seem quite fiddly to set up. Is there a better way?
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
They need to be able to select more than one option in each category - I don't think Data Validation can handle this?
 
Upvote 0
i would think it difficult to allow multi selections in data validation without having lots of redundant unused areas. maybe a userform with listboxes in it with multiselect enabled.

then loop through the listboxes to aquire your selections and the associated multipliers

then simple math to output the answer?
 
Upvote 0
no, like 1 listbox for channel that lists all the possible channels. 1 for product that lists all the products. etc.

i'm drafting up some example code right now for ya.
 
Upvote 0
Okay - that sounds like exactly what I was thinking about - but I didn't know if it existed (and all of my searches have been fruitless - grrr!)
 
Upvote 0
ok, make a new userform

on it, put 6 listboxes, 2 commandbuttons, and 1 label. space them out a little bit so you can see everything ok.

leave all their names defaulted (ListBox1, ListBox2... CommandButton1...)

then put this code into the module so you can see what i'm talking about.
when you run this, is total's the multipliers for any given selection, then multiplies them all together at the end.

Code:
Option Explicit
 
Private Sub CommandButton1_Click()
Dim choices As Integer, pick As Integer, a As Integer
Dim Multply(6) As Single, Answer As Single
    For choices = 1 To 6
        For pick = 0 To Me.Controls("ListBox" & choices).ListCount - 1
            With Me.Controls("ListBox" & choices)
                If .Selected(pick) Then
                    Multply(choices) = Multply(choices) + Multiplier(choices, pick)
                End If
            End With
        Next pick
        If Multply(choices) = 0 Then Multply(choices) = 1
    Next choices
    MsgBox "Will multiply these values:" & vbCrLf & _
           Multply(1) & vbCrLf & _
           Multply(2) & vbCrLf & _
           Multply(3) & vbCrLf & _
           Multply(4) & vbCrLf & _
           Multply(5) & vbCrLf & _
           Multply(6)
    Answer = 1 'answer has to start as 1, otherwise, it'll always be zero
    For a = 1 To 6 'a = 1 to the number of listboxes
        Answer = Multply(a) * Answer
    Next a
    Label1.Caption = Answer
End Sub
 
Private Function Multiplier(whichList As Integer, whichSelection As Integer) As Single
    Select Case whichList
 
    'this outer bunch of cases needs to have 1 case for each listbox
    'this example uses 6 so i have 6 outer cases
 
        Case 1: 'options in first listbox
            Select Case whichSelection + 1
            'these inner bunch of cases, need 1 for each possible selection for that box
            '(so a box with 4 options would have 4 cases here)
                Case 1: Multiplier = 1 'these numbers are the multipliers for each option
                Case 2: Multiplier = 2
                Case 3: Multiplier = 3
            End Select
        Case 2: 'options in second listbox
            Select Case whichSelection + 1
                Case 1: Multiplier = 1
                Case 2: Multiplier = 2
                Case 3: Multiplier = 3
            End Select
        Case 3: 'options in third listbox
            Select Case whichSelection + 1
                Case 1: Multiplier = 1
                Case 2: Multiplier = 2
                Case 3: Multiplier = 3
            End Select
        Case 4: 'options in fourth listbox
            Select Case whichSelection + 1
                Case 1: Multiplier = 1
                Case 2: Multiplier = 2
                Case 3: Multiplier = 3
            End Select
        Case 5: 'options in fifth listbox
            Select Case whichSelection + 1
                Case 1: Multiplier = 1
                Case 2: Multiplier = 2
                Case 3: Multiplier = 3
            End Select
        Case 6: 'options in sixth listbox
            Select Case whichSelection + 1
                Case 1: Multiplier = 1
                Case 2: Multiplier = 2
                Case 3: Multiplier = 3
            End Select
    End Select
End Function
 
Private Sub CommandButton2_Click()
    Unload Me
End Sub
 
Private Sub UserForm_Initialize()
    CommandButton1.Caption = "Calculate"
    CommandButton2.Caption = "Done"
    Label1.Font.Size = 20
    Label1.Caption = "answer"
 
    ListBox1.MultiSelect = fmMultiSelectMulti
    ListBox2.MultiSelect = fmMultiSelectMulti
    ListBox3.MultiSelect = fmMultiSelectMulti
    ListBox4.MultiSelect = fmMultiSelectMulti
    ListBox5.MultiSelect = fmMultiSelectMulti
    ListBox6.MultiSelect = fmMultiSelectMulti
 
    ListBox1.AddItem "#1, option 1"
    ListBox1.AddItem "#1, option 2"
    ListBox1.AddItem "#1, option 3"
 
    ListBox2.AddItem "#2, option 1"
    ListBox2.AddItem "#2, option 2"
    ListBox2.AddItem "#2, option 3"
 
    ListBox3.AddItem "#3, option 1"
    ListBox3.AddItem "#3, option 2"
    ListBox3.AddItem "#3, option 3"
 
    ListBox4.AddItem "#4, option 1"
    ListBox4.AddItem "#4, option 2"
    ListBox4.AddItem "#4, option 3"
 
    ListBox5.AddItem "#5, option 1"
    ListBox5.AddItem "#5, option 2"
    ListBox5.AddItem "#5, option 3"
 
    ListBox6.AddItem "#6, option 1"
    ListBox6.AddItem "#6, option 2"
    ListBox6.AddItem "#6, option 3"
End Sub
 
Last edited:
Upvote 0
no problem, i'm gonna edit it with some more comments to make it a little better to understand. give me a sec
 
Upvote 0

Forum statistics

Threads
1,225,155
Messages
6,183,211
Members
453,151
Latest member
Lizamaison

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top