Hello,
I am using a userform with comboboxes to collect information from the user. The user can decide to enter only 1 set of data which consist of 4 comboboxes (combobox #1-4). However, the user can also provide an optional 2nd set of data which repeat the same questions as the 1st set of data and use combobox #5-8. I would like then the data to be inputted into the worksheet when the user click on the button and that this data be group together under a single cell for each of the same question: for example combobox #1 and #5 are put into the same cell B2, combox #2 and #6 in cell C2, etc. I was able to accomplish that.
My problem is that I would like to group together only the data for the 1st and 2nd set of data if they are different. So if the answer to combobox #1 and #5 are the same, I don’t want them to be repeated twice in the same cell as there is no need for that (I just want 1 of the same answer) but if the answer of combox #2 and #6 are different then I would like to see those 2 different answers in the same cells.
I have included a sample file as well as the part of the code below and in red where I believe where it needs to be updated. Thank you for your time and help!
Private Sub cmdAdd_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Entry")
'find first empty row in database
iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
'check for a part number
If Trim(Me.ComboBox1.Value) = "" Then
Me.ComboBox1.SetFocus
MsgBox "Please enter a Vehicule type"
Exit Sub
End If
'copy the data to the database
'use protect and unprotect lines,
' with your password
' if worksheet is protected
With ws
' .Unprotect Password:="password"
.Cells(iRow, 2).Value = Me.ComboBox1.Value & " " & ComboBox5.Value
.Cells(iRow, 3).Value = Me.ComboBox2.Value & " " & ComboBox6.Value
.Cells(iRow, 4).Value = Me.ComboBox3.Value & " " & ComboBox7.Value
.Cells(iRow, 5).Value = Me.ComboBox4.Value & " " & ComboBox8.Value
' .Protect Password:="password"
End With
'clear the data
Me.ComboBox1.Value = ""
Me.ComboBox2.Value = ""
Me.ComboBox3.Value = ""
Me.ComboBox4.Value = ""
Me.ComboBox5.Value = ""
Me.ComboBox6.Value = ""
Me.ComboBox7.Value = ""
Me.ComboBox8.Value = ""
Me.ComboBox1.SetFocus
End Sub
'Source for command add button example:http://www.contextures.com/xlUserForm01.html
Bookmarks