ExtraCheese
New Member
- Joined
- Sep 18, 2020
- Messages
- 16
- Office Version
- 2016
- Platform
- Windows
I have a userform with 3 listboxes and 1 textbox. The first listbox gives 8 unique timeslots, the second listbox a choice, and the third listbox another choice, based on the choice from listbox 2.
The code I use transforms the data into the tab 'data', which is working perfectly.
The user can pick a timeslot, then answer listbox 2 and listbox 3, then fill in the textbox (which is irrelevant for now).
What I want to prevent is that a user can pick the same choice combination per timeslot (e.g. timeslot 08:00, choice a and choice a). It is ok he can pick the same choice in a different timeslot though (e.g. timeslot 09:00, choice a and choice a).
Code:
Private Sub CommandButton1_Click()
Dim RecordRow As Long, RecordColumn As Long
RecordRow = Me.ListBox1.ListIndex + 7
RecordColumn = Me.ListBox2.ListIndex + 13
Cells(RecordRow, RecordColumn).Value = Me.TextBox1.Value
Dim irow As Long
Dim ws As Worksheet
Set ws = Worksheets("Data")
irow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
With ws
.Range("A" & irow) = ListBox1.Value
.Range("B" & irow) = ListBox2.Value
.Range("C" & irow) = ListBox3.Value
.Range("D" & irow) = TextBox1.Value
End With
ListBox1.Value = ""
ListBox2.Value = ""
ListBox3.Value = ""
TextBox1.Value = ""
End Sub
The code I use transforms the data into the tab 'data', which is working perfectly.
The user can pick a timeslot, then answer listbox 2 and listbox 3, then fill in the textbox (which is irrelevant for now).
What I want to prevent is that a user can pick the same choice combination per timeslot (e.g. timeslot 08:00, choice a and choice a). It is ok he can pick the same choice in a different timeslot though (e.g. timeslot 09:00, choice a and choice a).
Code:
Private Sub CommandButton1_Click()
Dim RecordRow As Long, RecordColumn As Long
RecordRow = Me.ListBox1.ListIndex + 7
RecordColumn = Me.ListBox2.ListIndex + 13
Cells(RecordRow, RecordColumn).Value = Me.TextBox1.Value
Dim irow As Long
Dim ws As Worksheet
Set ws = Worksheets("Data")
irow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
With ws
.Range("A" & irow) = ListBox1.Value
.Range("B" & irow) = ListBox2.Value
.Range("C" & irow) = ListBox3.Value
.Range("D" & irow) = TextBox1.Value
End With
ListBox1.Value = ""
ListBox2.Value = ""
ListBox3.Value = ""
TextBox1.Value = ""
End Sub