View Full Version : Solved: Checkbox with userform
slamet Harto
03-04-2009, 09:46 PM
Hi there,
Can you help me with the checkbox in a userform.
If the user ticked for both of the checkbox then will copy to new row with the same as the user entered.
please find the attached for your reference.
Thank you for assistance.
Rgds, Harto
Greetings Harto,
It may well just be me, but I am a tiny bit unclear as to what you are looking to do exactly.
I think I get that you want one row to get filled in if the user ticks one box, and of course two rows filled if the user checks both boxes.
However, in a place or two, you refer to 'Sheets(1)' which is of course just a sheet's index (what happens if the user re-orders the sheets?), but in another place you are explicit in using a sheet's CodeName (Sheet1).
Anyways, that confused me a bit, but try this and see if I'm at least headed in the right direction?
Mark
Private Sub CommandButton1_Click()
Dim NRow As Integer
Sheets(1).Activate
With Sheets(1)
If TextBox2.Text = "" Then
MsgBox "enter Cust Name"
Exit Sub
End If
If TextBox3.Text = "" Then
MsgBox "enter pass code"
Exit Sub
End If
If Not CheckBox1 _
And Not CheckBox2 Then
MsgBox "You must tick at least one of the checkbox!", vbCritical, "Error Message"
Exit Sub
End If
If CheckBox1 Then
NRow = WorksheetFunction.CountA(.Range("B:B")) + 2
Sheet1.Range(Cells(NRow, 1), Cells(NRow, 4)) = _
Array(TextBox1, "Program1", TextBox2, TextBox3)
End If
If CheckBox2 Then
NRow = WorksheetFunction.CountA(.Range("B:B")) + 2
Sheet1.Range(Cells(NRow, 1), Cells(NRow, 4)) = _
Array(TextBox1, "Program2", TextBox2, TextBox3)
End If
End With
Unload Me
End Sub
Chris Bode
03-04-2009, 11:43 PM
Please try following codes
Private Sub CommandButton1_Click()
Dim row As Integer, col As Integer
row = 3
col = 1
While Sheet1.Cells(row, col).Value <> ""
row = row + 1
Wend
If CheckBox1.Value = True And CheckBox2.Value = True Then
Sheet1.Cells(row, col).Value = txtNO.Text
Sheet1.Cells(row, col + 1).Value = "Program 1"
Sheet1.Cells(row, col + 2).Value = txtName.Text
Sheet1.Cells(row, col + 3).Value = txtPassCode.Text
row = row + 1
Sheet1.Cells(row, col).Value = txtNO.Text
Sheet1.Cells(row, col + 1).Value = "Program 2"
Sheet1.Cells(row, col + 2).Value = txtName.Text
Sheet1.Cells(row, col + 3).Value = txtPassCode.Text
Exit Sub
End If
If CheckBox1.Value = True Then
Sheet1.Cells(row, col).Value = txtNO.Text
Sheet1.Cells(row, col + 1).Value = "Program 1"
Sheet1.Cells(row, col + 2).Value = txtName.Text
Sheet1.Cells(row, col + 3).Value = txtPassCode.Text
ElseIf CheckBox2.Value = True Then
Sheet1.Cells(row, col).Value = txtNO.Text
Sheet1.Cells(row, col + 1).Value = "Program 2"
Sheet1.Cells(row, col + 2).Value = txtName.Text
Sheet1.Cells(row, col + 3).Value = txtPassCode.Text
End If
End Sub
slamet Harto
03-05-2009, 12:03 AM
Hi Mark,
Long time no speak, thanks for quick response.
Chris,
Work well. Thank you so much for your kind assistance.
Highly appreciate it.
Best, Harto
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.