PDA

View Full Version : Solved: Choosen some checkbox



slamet Harto
09-17-2008, 08:53 PM
Hi there,

Can you help to advise me with some checkbox in userform based on option.
Option number1 if checkbox1 value is true then write type with ?CCC?, if Checkbox2 value is true then write ?DDD?, If checkbox3 value is true then write
?EEE? and so on.

In this case, we are allowing the user to choose both of them or all Type.
If all type then, write them all type with ?CCC?, DDD until FFF.

Please advise.
Thanks a bunch.
Rgds, harto

Private Sub CMDButton_Click()
Dim NRowBaru As Integer
If TextBox5.Text = "" Then
MsgBox "please enter firs name!"
TextBox5.SetFocus
Exit Sub
End If
If ComboBox2.Value = "" Then
MsgBox "select the tittle"
ComboBox2.SetFocus
End If
If CheckBox1.Value = False Or CheckBox2.Value = False Or CheckBox3.Value = False Or CheckBox4.Value = False Or CheckBox5.Value = False Then
MsgBox "You must tick at least one of the checkbox"
CheckBox1.SetFocus
CheckBox2.SetFocus
CheckBox3.SetFocus
CheckBox4.SetFocus
CheckBox5.SetFocus
Exit Sub
End If
With Sheets(2)
NRowBaru = WorksheetFunction.CountA(.Range("B:B")) + 4
If CheckBox5.Value = True Then
.Cells(NRowBaru, 1).Value = "CCC"
.Cells(NRowBaru, 2).Value = ComboBox2.Value
.Cells(NRowBaru, 3).Value = TextBox5.Text
.Cells(NRowBaru, 1).Value = TextBox6.Text
NRowBaru = NRowBaru + 1
.Cells(NRowBaru, 1).Value = "DDD"
.Cells(NRowBaru, 2).Value = ComboBox2.Value
.Cells(NRowBaru, 3).Value = TextBox5.Text
.Cells(NRowBaru, 1).Value = TextBox6.Text
NRowBaru = NRowBaru + 1
.Cells(NRowBaru, 1).Value = "EEE"
.Cells(NRowBaru, 2).Value = ComboBox2.Value
.Cells(NRowBaru, 3).Value = TextBox5.Text
.Cells(NRowBaru, 1).Value = TextBox6.Text
NRowBaru = NRowBaru + 1
.Cells(NRowBaru, 1).Value = "FFF"
.Cells(NRowBaru, 2).Value = ComboBox2.Value
.Cells(NRowBaru, 3).Value = TextBox5.Text
.Cells(NRowBaru, 1).Value = TextBox6.Text
ElseIf CheckBox1.Value = True Or CheckBox2.Value = True Then

.Cells(NRowBaru, 1).Value = "CCC"
.Cells(NRowBaru, 2).Value = ComboBox2.Value
.Cells(NRowBaru, 3).Value = TextBox5.Text
.Cells(NRowBaru, 1).Value = TextBox6.Text
NRowBaru = NRowBaru + 1
.Cells(NRowBaru, 1).Value = "DDD"
.Cells(NRowBaru, 2).Value = ComboBox2.Value
.Cells(NRowBaru, 3).Value = TextBox5.Text
.Cells(NRowBaru, 1).Value = TextBox6.Text

ElseIf CheckBox3.Value = True Or CheckBox4.Value = True Then
.Cells(NRowBaru, 1).Value = "EEE"
.Cells(NRowBaru, 2).Value = ComboBox2.Value
.Cells(NRowBaru, 3).Value = TextBox5.Text
.Cells(NRowBaru, 1).Value = TextBox6.Text
NRowBaru = NRowBaru + 1
.Cells(NRowBaru, 1).Value = "FFF"
.Cells(NRowBaru, 2).Value = ComboBox2.Value
.Cells(NRowBaru, 3).Value = TextBox5.Text
.Cells(NRowBaru, 1).Value = TextBox6.Text
Else
.Cells(NRowBaru, 1).Value = CheckBox1
.Cells(NRowBaru, 2).Value = ComboBox2.Value
.Cells(NRowBaru, 3).Value = TextBox5.Text
.Cells(NRowBaru, 1).Value = TextBox6.Text

End If
Call tosetfocus
End With
Range("A4").Select
Unload Me
End Sub
Private Sub togetfocus()
ComboBox2.Value = ""
ComboBox4.Value = ""
TextBox5.Text = ""
TextBox6.Text = ""

End Sub

Bob Phillips
09-18-2008, 12:28 AM
Private Sub CMDButton_Click()
Dim NRowBaru As Integer

If TextBox5.Text = "" Then
MsgBox "please enter first name!"
TextBox5.SetFocus
Exit Sub
End If
If ComboBox2.Value = "" Then
MsgBox "select the tittle"
ComboBox2.SetFocus
Exit Sub
End If
If CheckBox1.Value = False And CheckBox2.Value = False And _
CheckBox3.Value = False And CheckBox4.Value = False And _
CheckBox5.Value = False Then
MsgBox "You must tick at least one of the checkbox"
CheckBox1.SetFocus
Exit Sub
End If

With Sheets(2)
NRowBaru = WorksheetFunction.CountA(.Range("B:B")) + 4

If CheckBox5.Value = True Then
.Cells(NRowBaru, 1).Value = "CCC"
.Cells(NRowBaru, 2).Value = ComboBox2.Value
.Cells(NRowBaru, 3).Value = TextBox5.Text
.Cells(NRowBaru, 1).Value = TextBox6.Text
NRowBaru = NRowBaru + 1
.Cells(NRowBaru, 1).Value = "DDD"
.Cells(NRowBaru, 2).Value = ComboBox2.Value
.Cells(NRowBaru, 3).Value = TextBox5.Text
.Cells(NRowBaru, 1).Value = TextBox6.Text
NRowBaru = NRowBaru + 1
.Cells(NRowBaru, 1).Value = "EEE"
.Cells(NRowBaru, 2).Value = ComboBox2.Value
.Cells(NRowBaru, 3).Value = TextBox5.Text
.Cells(NRowBaru, 1).Value = TextBox6.Text
NRowBaru = NRowBaru + 1
.Cells(NRowBaru, 1).Value = "FFF"
.Cells(NRowBaru, 2).Value = ComboBox2.Value
.Cells(NRowBaru, 3).Value = TextBox5.Text
.Cells(NRowBaru, 1).Value = TextBox6.Text

ElseIf CheckBox1.Value = True Or CheckBox2.Value = True Then

.Cells(NRowBaru, 1).Value = "CCC"
.Cells(NRowBaru, 2).Value = ComboBox2.Value
.Cells(NRowBaru, 3).Value = TextBox5.Text
.Cells(NRowBaru, 1).Value = TextBox6.Text
NRowBaru = NRowBaru + 1
.Cells(NRowBaru, 1).Value = "DDD"
.Cells(NRowBaru, 2).Value = ComboBox2.Value
.Cells(NRowBaru, 3).Value = TextBox5.Text
.Cells(NRowBaru, 1).Value = TextBox6.Text

ElseIf CheckBox3.Value = True Or CheckBox4.Value = True Then
.Cells(NRowBaru, 1).Value = "EEE"
.Cells(NRowBaru, 2).Value = ComboBox2.Value
.Cells(NRowBaru, 3).Value = TextBox5.Text
.Cells(NRowBaru, 1).Value = TextBox6.Text
NRowBaru = NRowBaru + 1
.Cells(NRowBaru, 1).Value = "FFF"
.Cells(NRowBaru, 2).Value = ComboBox2.Value
.Cells(NRowBaru, 3).Value = TextBox5.Text
.Cells(NRowBaru, 1).Value = TextBox6.Text
Else
.Cells(NRowBaru, 1).Value = CheckBox1
.Cells(NRowBaru, 2).Value = ComboBox2.Value
.Cells(NRowBaru, 3).Value = TextBox5.Text
.Cells(NRowBaru, 1).Value = TextBox6.Text

End If

Call tosetfocus
End With

Range("A4").Select
Unload Me
End Sub

Bob Phillips
09-18-2008, 12:29 AM
BTW, I would take the OK/Close buttons off of the multipage, so you only have one set not two.

GTO
09-18-2008, 01:05 AM
I'm afraid I didn't follow along with the two pages very well, but from your narrative, I believe this would work :-)

(See sheet 3)


Option Explicit
Private Sub cmdOKBttn_Click()

If cboTitle.Value = Empty Then
MsgBox "Please select a title!", 0, ""
cboTitle.SetFocus
Exit Sub
End If
If txtFNam.Value = Empty Then
MsgBox "Please enter the first name.", 0, ""
txtFNam.SetFocus
Exit Sub
End If
If txtLNam.Value = Empty Then
MsgBox "Please enter the last name.", 0, ""
txtLNam.SetFocus
Exit Sub
End If
If Not chk_1 _
And Not chk_2 _
And Not chk_3 _
And Not chk_4 _
And Not chk_5 Then
MsgBox "You must select at least one TYPE", 0, ""
Exit Sub
End If

If chk_5 Then
Sheet3.Range(Cells(NRowNaru, 1), Cells(NRowNaru, 4)) = _
Array("CCC", cboTitle, txtFNam, txtLNam)
Sheet3.Range(Cells(NRowNaru, 1), Cells(NRowNaru, 4)) = _
Array("DDD", cboTitle, txtFNam, txtLNam)
Sheet3.Range(Cells(NRowNaru, 1), Cells(NRowNaru, 4)) = _
Array("EEE", cboTitle, txtFNam, txtLNam)
Sheet3.Range(Cells(NRowNaru, 1), Cells(NRowNaru, 4)) = _
Array("FFF", cboTitle, txtFNam, txtLNam)
Else
If chk_1 Then
Sheet3.Range(Cells(NRowNaru, 1), Cells(NRowNaru, 4)) = _
Array("CCC", cboTitle, txtFNam, txtLNam)
End If
If chk_2 Then
Sheet3.Range(Cells(NRowNaru, 1), Cells(NRowNaru, 4)) = _
Array("DDD", cboTitle, txtFNam, txtLNam)
End If
If chk_3 Then
Sheet3.Range(Cells(NRowNaru, 1), Cells(NRowNaru, 4)) = _
Array("EEE", cboTitle, txtFNam, txtLNam)
End If
If chk_4 Then
Sheet3.Range(Cells(NRowNaru, 1), Cells(NRowNaru, 4)) = _
Array("FFF", cboTitle, txtFNam, txtLNam)
End If
End If

Unload Me
End Sub
Private Function NRowNaru() As Long
Dim rngCell As Range
NRowNaru = 4
Set rngCell = Sheet3.Range("A4")
Do While rngCell.Value <> ""
Set rngCell = Sheet3.Cells(NRowNaru, 1).Offset(1, 0)
NRowNaru = NRowNaru + 1
Loop
End Function
Private Sub cmdUnloadBttn_Click()
Unload Me
End Sub
Private Sub UserForm_Initialize()
frmExample.cboTitle.List() = Array("Mr.", "Mrs.", "MS.")
End Sub

Bob Phillips
09-18-2008, 01:14 AM
I don't know what your point/question is?

slamet Harto
09-18-2008, 06:59 PM
Dear Bob and GTO.

Work nice. I've learned much from you all.
Thank you for your support and assistance.

Best, Harto