Hi,
I've been trying to write out a code for ticking off multiple check boxes so that the resultant values comes in one cell separated by a comma. Below is the code I've written it out.
It'd be really helpful if someone can help me figure out what's wrong with this code.
Thanks
Code
Private Sub cmdSave_Click()
Dim lngWriteRow As Long
Dim ws As Worksheet
Set ws = Worksheets("details")
lngWriteRow = ws.Cells(Rows.Count, 7) _
.End(xlUp).Offset(1, 0).Row
ws.Range("A" & lngWriteRow) = txtFirstName.Value
ws.Range("B" & lngWriteRow) = txtLastName.Value
ws.Range("C" & lngWriteRow) = txtPosition.Value
ws.Range("D" & lngWriteRow) = txtCompany.Value
ws.Range("E" & lngWriteRow) = txtEmail.Value
ws.Range("F" & lngWriteRow) = txtPhoneW.Value
ws.Range("G" & lngWriteRow) = txtPhoneM.Value
ws.Range("H" & lngWriteRow) = txtAddress.Value
If CheckBox1.Value = True Then
ws.Range("J" & lngWriteRow) = "Construction"
End If
If CheckBox2.Value = True Then
ws.Range("J" & lngWriteRow) = ws.Range("J" & lngWriteRow) & IIf(ws.Range("J", lngWriteRow) <> "", ",", "") & "Infrastructure"
End If
If CheckBox3.Value = True Then
ws.Range("J" & lngWriteRow) = ws.Range("J" & lngWriteRow) & IIf(ws.Range("J", lngWriteRow) <> "", ",", "") & "Consultant"
End If
If CheckBox4.Value = True Then
ws.Range("J" & lngWriteRow) = ws.Range("J" & lngWriteRow) & IIf(ws.Range("J", lngWriteRow) <> "", ",", "") & "Resources/Mining"
End If
If CheckBox5.Value = True Then
ws.Range("J" & lngWriteRow) = ws.Range("J" & lngWriteRow) & IIf(ws.Range("J", lngWriteRow) <> "", ",", "") & "Supplier"
End If
If CheckBox6.Value = True Then
ws.Range("J" & lngWriteRow) = ws.Range("J" & lngWriteRow) & IIf(ws.Range("J", lngWriteRow) <> "", ",", "") & "Education"
End If
If CheckBox7.Value = True Then
ws.Range("J" & lngWriteRow) = ws.Range("J" & lngWriteRow) & IIf(ws.Range("J", lngWriteRow) <> "", ",", "") & "Competitor"
End If
If CheckBox8.Value = True Then
ws.Range("J" & lngWriteRow) = ws.Range("J" & lngWriteRow) & IIf(ws.Range("J", lngWriteRow) <> "", ",", "") & "Friend"
End If
If CheckBox9.Value = True Then
ws.Range("J" & lngWriteRow) = ws.Range("J" & lngWriteRow) & IIf(ws.Range("J", lngWriteRow) <> "", ",", "") & "Government"
End If
If CheckBox10.Value = True Then
ws.Range("J" & lngWriteRow) = ws.Range("J" & lngWriteRow) & IIf(ws.Range("J", lngWriteRow) <> "", ",", "") & "Commercial Retail"
End If
If CheckBox11.Value = True Then
ws.Range("J" & lngWriteRow) = ws.Range("J" & lngWriteRow) & IIf(ws.Range("J", lngWriteRow) <> "", ",", "") & "Private Company"
End If
If CheckBox12.Value = True Then
ws.Range("J" & lngWriteRow) = ws.Range("J" & lngWriteRow) & IIf(ws.Range("J", lngWriteRow) <> "", ",", "") & "Health Planning"
End If
End Sub
Display More