Quick User Form question

mahmed1

Well-known Member
Joined
Mar 28, 2009
Messages
2,176
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
 

Some videos you may like

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

mahmed1

Well-known Member
Joined
Mar 28, 2009
Messages
2,176
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


Bump
 

Watch MrExcel Video

Forum statistics

Threads
1,109,032
Messages
5,526,360
Members
409,697
Latest member
christopherlewis1620

This Week's Hot Topics

Top