Quick User Form question

mahmed1

Well-known Member
Joined
Mar 28, 2009
Messages
2,302
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi Guys,

This code works fine. The only problem i have is that when i enter the number with a 0 in front i.e 0121454, when i press ok on the user form, it misses the 0 out. I have rectified this by pre formatting the cells that the number will go in as text however i have this problem where it always shows the error message drop down (i.e - Number stored as text, convert to number, Help on this error) etc.... How can i get rid of this.


Code:
Private Sub CancelButton_Click()
Unload Me
End Sub
Private Sub ClearButton_Click()
Call UserForm_Initialize
End Sub
Private Sub MoneySpinButton_Change()
MoneyTextBox.Text = MoneySpinButton.Value
End Sub
Private Sub OKButton_Click()
Dim emptyRow As Long
'Make Sheet1 Active
Sheets(1).Activate
'Determine EmptyRow
emptyRow = WorksheetFunction.CountA(Range("B:B")) + 1
'Export Data to worksheet
Cells(emptyRow, 2).Value = NameTextBox.Value
Cells(emptyRow, 3).Value = PhoneTextBox.Value
Cells(emptyRow, 4).Value = CityListBox.Value
Cells(emptyRow, 5).Value = DinnerComboBox.Value
If DateCheckBox1.Value = True Then Cells(emptyRow, 6).Value = DateCheckBox1.Caption
If DateCheckBox2.Value = True Then Cells(emptyRow, 6).Value = Cells(emptyRow, 6).Value & " " & DateCheckBox2.Caption
If DateCheckBox3.Value = True Then Cells(emptyRow, 6).Value = Cells(emptyRow, 6).Value & " " & DateCheckBox3.Caption
If CarOptionButton1.Value = True Then
    Cells(emptyRow, 7).Value = "Yes"
Else
    Cells(emptyRow, 7).Value = "No"
End If
Cells(emptyRow, 8).Value = MoneyTextBox.Value
End Sub
Private Sub UserForm_Initialize()
'Empty NameTextBox
NameTextBox.Value = ""
'Empty PhoneTextBox
PhoneTextBox.Value = ""
'Empty CityListBox
CityListBox.Clear
'Fill CityListBox
With CityListBox
    .AddItem "San Fransisco"
    .AddItem "Oakland"
    .AddItem "Richmond"
End With
'Empty DinnerComboBox
DinnerComboBox.Clear
'Fill DinnerComboBox
With DinnerComboBox
    .AddItem "Italian"
    .AddItem "Chinese"
    .AddItem "Frites and Meat"
End With
'Uncheck DataCheckBoxes
DateCheckBox1.Value = False
DateCheckBox2.Value = False
DateCheckBox3.Value = False
'Set no car as default
CarOptionButton2.Value = True
'Empty MoneyTextBox
MoneyTextBox.Value = ""
'Set Focus on NameTextBox
NameTextBox.SetFocus
End Sub
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Hi Guys,

This code works fine. The only problem i have is that when i enter the number with a 0 in front i.e 0121454, when i press ok on the user form, it misses the 0 out. I have rectified this by pre formatting the cells that the number will go in as text however i have this problem where it always shows the error message drop down (i.e - Number stored as text, convert to number, Help on this error) etc.... How can i get rid of this.


Code:
Private Sub CancelButton_Click()
Unload Me
End Sub
Private Sub ClearButton_Click()
Call UserForm_Initialize
End Sub
Private Sub MoneySpinButton_Change()
MoneyTextBox.Text = MoneySpinButton.Value
End Sub
Private Sub OKButton_Click()
Dim emptyRow As Long
'Make Sheet1 Active
Sheets(1).Activate
'Determine EmptyRow
emptyRow = WorksheetFunction.CountA(Range("B:B")) + 1
'Export Data to worksheet
Cells(emptyRow, 2).Value = NameTextBox.Value
Cells(emptyRow, 3).Value = PhoneTextBox.Value
Cells(emptyRow, 4).Value = CityListBox.Value
Cells(emptyRow, 5).Value = DinnerComboBox.Value
If DateCheckBox1.Value = True Then Cells(emptyRow, 6).Value = DateCheckBox1.Caption
If DateCheckBox2.Value = True Then Cells(emptyRow, 6).Value = Cells(emptyRow, 6).Value & " " & DateCheckBox2.Caption
If DateCheckBox3.Value = True Then Cells(emptyRow, 6).Value = Cells(emptyRow, 6).Value & " " & DateCheckBox3.Caption
If CarOptionButton1.Value = True Then
    Cells(emptyRow, 7).Value = "Yes"
Else
    Cells(emptyRow, 7).Value = "No"
End If
Cells(emptyRow, 8).Value = MoneyTextBox.Value
End Sub
Private Sub UserForm_Initialize()
'Empty NameTextBox
NameTextBox.Value = ""
'Empty PhoneTextBox
PhoneTextBox.Value = ""
'Empty CityListBox
CityListBox.Clear
'Fill CityListBox
With CityListBox
    .AddItem "San Fransisco"
    .AddItem "Oakland"
    .AddItem "Richmond"
End With
'Empty DinnerComboBox
DinnerComboBox.Clear
'Fill DinnerComboBox
With DinnerComboBox
    .AddItem "Italian"
    .AddItem "Chinese"
    .AddItem "Frites and Meat"
End With
'Uncheck DataCheckBoxes
DateCheckBox1.Value = False
DateCheckBox2.Value = False
DateCheckBox3.Value = False
'Set no car as default
CarOptionButton2.Value = True
'Empty MoneyTextBox
MoneyTextBox.Value = ""
'Set Focus on NameTextBox
NameTextBox.SetFocus
End Sub


Bump
 
Upvote 0

Forum statistics

Threads
1,213,482
Messages
6,113,915
Members
448,532
Latest member
9Kimo3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top