Hi all,
I am writing a simple user form to get data entered directly into cells in a spreadsheet. I have a combo box(ListBox1) and a TextBox(TextBox1) in the user form. I would like to erase the previous values entered each time the user form is loaded. I have included statements for this in the Initialize sub routine but for some reason this does not seem to work.
Also, I would like to allow value to be entered from only one of the two possible ways to enter data i.e listbox or the textbox. What happens with my code is that If there are values in both the boxes, the value from the listbox is taken and entered. I am not sure how to proceed with it. The code that I have used is as follows:
[pre]
[/pre]
It would be great if anybody can help me out on this.
Thank You in advance.
I am writing a simple user form to get data entered directly into cells in a spreadsheet. I have a combo box(ListBox1) and a TextBox(TextBox1) in the user form. I would like to erase the previous values entered each time the user form is loaded. I have included statements for this in the Initialize sub routine but for some reason this does not seem to work.
Also, I would like to allow value to be entered from only one of the two possible ways to enter data i.e listbox or the textbox. What happens with my code is that If there are values in both the boxes, the value from the listbox is taken and entered. I am not sure how to proceed with it. The code that I have used is as follows:
[pre]
Code:
Private Sub OKBtn_Click()
If Len(Me.ListBox1.Value) + Len(Me.TextBox1.Value) = 0 Then
MsgBox "Please enter an option..", vbExclamation, "Data"
Me.TextBox1.SetFocus
ElseIf Len(Me.ListBox1.Value) <> 0 Then
ActiveCell.Value = ListBox1.Value
Me.Hide
ElseIf Len(TextBox1.Value) <> 0 Then
ActiveCell.Value = TextBox1.Value
Me.Hide
End If
End Sub
Private Sub Cancel_Click()
Unload Me
End Sub
Private Sub UserForm_Initialize()
ListBox1.Value = ""
TextBox1.Value = ""
End Sub
It would be great if anybody can help me out on this.
Thank You in advance.