Format from a textbox in a userform

brianfosterblack

Active Member
Joined
Nov 1, 2011
Messages
251
I am using the following code to take the content from a userform and place it in certain cells in a spreadsheet
ActiveCell.Value = FrmSale.TextBox2
Selection.NumberFormat = "d/m/yyyy"
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = FrmSale.TextBox3

The problem I am having is that everything is just being entered into all the cells as text
Some Textboxes are dates and they must enter as dates d/m/yyyy
some are whole numbers
some are numbers which must have 2 decimal points after the number e.g 5 entered as 5.00
some are percentages which must have 2 decimal points after the number. In the textbox could be the number 100 but this must enter in the speadsheet as 100% so I guess this should also have a formula to divide by 100 if the number is being represented as a percentage.

Can someone please help with this or point me to somewhere on the internet where I can find the answers.
 
Hi,

It was only the first 2 textboxes with dates in that I was having the problem with I I do not remember the error types I was getting.. The other textboxes are calculated dates based on a formula where I use Datevalue( in the formula to calculate the date. The problem I am finding however is that I have allowed a date for the birthdate of up to 6 children and where the textbox is empty (because there are less than 6 children) then I get the error "Runtime Error 13', type mismatch. I understand that I am getting this problem because the textbox is empty. Do I have to run this as an if function to first check if the textbox is empty? the same happens with a textbox if I am using CLng(.....
 
Upvote 0

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Sorry that is the lack of experience coming out in me.

What I am saying is if I have the code
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = CLng(FrmSale.TextBox3)
But the textbox is actually left empty because there is no data to fill in, then I get the error message 13' type mismatch. Do I need to put in code to test if the textbox is empty or not before using the code CLng(FrmSale.TextBox3)?
 
Upvote 0
It's common practice to validate textbox entries to avoid errors and wrong data.

If IsDate(FrmSale.TextBox3) Then
 
Upvote 0

Forum statistics

Threads
1,215,422
Messages
6,124,808
Members
449,191
Latest member
rscraig11

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