Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel User Form VBA Code

Status
Not open for further replies.

Dawber

Technical User
Jun 29, 2001
86
GB
Could someone please solve this Excel User Form problem.

In the User Form I have a text box (TextBox1), a series of check boxes (ChechBox1, 2 & 3) and an execute button (CommandButton1). If a user checks boxes 1 and 3, I want adjacent cells to be filled with the relevant text. Unfortunately this routine ends at the first false return. I realise that it’s probably obvious but could you or someone please tell me why?

Private Sub CommandButton1_Click()
Dim xxx
xxx = TextBox1.Text

If CheckBox1.Value = True Then
ActiveCell.FormulaR1C1 = "1 " & xxx
ActiveCell.Offset(1, 0).Range("A1").Select

If CheckBox2.Value = True Then
ActiveCell.FormulaR1C1 = "2 " & xxx
ActiveCell.Offset(1, 0).Range("A1").Select

If CheckBox3.Value = True Then
ActiveCell.FormulaR1C1 = "3 " & xxx
ActiveCell.Offset(1, 0).Range("A1").Select

End If
End If
End If

End Sub
 
Hi there - you're just over complicating it - you need to run each if individually.

Hope this helps

Regards,

Miranda

see below:-


Private Sub CommandButton1_Click()
Dim xxx As String

xxx = TextBox1.Text

If CheckBox1.Value = True Then
ActiveCell.FormulaR1C1 = "1 " & xxx
ActiveCell.Offset(1, 0).Range("A1").Select
End If
If CheckBox2.Value = True Then
ActiveCell.FormulaR1C1 = "2 " & xxx
ActiveCell.Offset(1, 0).Range("A1").Select
End If
If CheckBox3.Value = True Then
ActiveCell.FormulaR1C1 = "3 " & xxx
ActiveCell.Offset(1, 0).Range("A1").Select
End If

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top