Dear people,
hope that all is well. I desperately need your help. Hoping to at least receive some feedback.
So, below is the code. What I need to do is to have an If statement if the sum of the two selections of the listboxes is smaller/bigger than a certain value.
I suspect it has something to do with there being a multiselect listboxes. To be clear, one should only be able to select one value in each listbox. Hopefully it makes sense what I'm trying to do. The relevant text is marked in red.
Many thanks in advance!
"
"
hope that all is well. I desperately need your help. Hoping to at least receive some feedback.
So, below is the code. What I need to do is to have an If statement if the sum of the two selections of the listboxes is smaller/bigger than a certain value.
I suspect it has something to do with there being a multiselect listboxes. To be clear, one should only be able to select one value in each listbox. Hopefully it makes sense what I'm trying to do. The relevant text is marked in red.
Many thanks in advance!
"
Code:
Private Sub UserForm_initialize()
'Clear listbox1
ListBox1.Value = ""
'Clear listbox2
ListBox2.Value = ""
'Clear listbox3
ListBox3.Value = ""
'Clear textbox1
TextBox1.Value = ""
'Fill listbox 1
With ListBox1
.AddItem "Aff?rsm?ssig skada"
.AddItem "Ekonomisk & regulatorisk skada"
End With
'Fill ListBox2
With ListBox2
.AddItem "3"
.AddItem "2"
.AddItem "1"
.AddItem "0"
End With
'Fill listbox3
With ListBox3
.AddItem "3"
.AddItem "2"
.AddItem "1"
.AddItem "0"
End With
End Sub
Private Sub CommandButton1_Click()
Dim row, startrow, lastrow As Long
Dim i, col As Variant
Dim ws As Worksheet
'make sheet "Incidenter" active
Sheets("Instruktioner").Activate
Set ws = Sheets("Incidenter")
i = row
col = "B"
lastrow = ws.Cells(Rows.Count, col).End(xlUp).row
'to ensure that incidents with small impact receives a message that the incident is not serious enough to be documented and that we remain on the main page
If[COLOR=#ff0000] ListBox2.Value + ListBox3.Value <= "3" Then[/COLOR]
Sheets("Instruktioner").Activate
MsgBox ("K?ra du, din incident har noterats och bed?ms inte vara tillr?ckligt seri?s f?r att incidentrapporteras. Kyss mig!")
End If
'to ensure that only serious breaches are added to the incident documentation
If [COLOR=#ff0000]ListBox3.Value + ListBox2.Value >= "4" Then[/COLOR]
'to copy the last row
ws.Rows(lastrow).Copy
'add another row at the bottom
ws.Rows(lastrow + 1).Insert
'To transfer input data into the table
ws.Cells(lastrow + 1, 2).Value = TextBox1.Value
ws.Cells(lastrow + 1, 3).Value = TextBox4.Value
ws.Cells(lastrow + 1, 4).Value = ListBox1.Value
ws.Cells(lastrow + 1, 5).Value = TextBox2.Value
ws.Cells(lastrow + 1, 6).Value = TextBox3.Value
ws.Cells(lastrow + 1, 7).Value = ListBox2.Value
ws.Cells(lastrow + 1, 8).Value = ListBox3.Value
ws.Cells(lastrow + 1, 10).Value = ""
ws.Cells(lastrow + 1, 11).Value = ""
MsgBox ("K?ra du, din incident har dokumenterats. Kyss mig!")
End If
Unload UserForm1
UserForm1.Hide
End Sub
Last edited by a moderator: