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

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
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,224,586
Messages
6,179,710
Members
452,939
Latest member
WCrawford

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