Hi!
I have a userform with a textbox and a commandbutton. The textbox value must be written on a cell. Both the textbox and the cell, must show a number with thousand separator and no decimal places. The thing is that I don't know if I should use the Format
function or the CDbl function, because one workmate says I must write the code like this:
Application.Goto ActiveWorkbook.Sheets("sheet2").Cells(8, 3) 'Enter data
ActiveCell.FormulaR1C1 = Format(TextBox1, "#")
Private Sub TextBox1_Change()
TextBox1 = Format(TextBox1, "#,###")
End Sub
And the other one tells me I must write it like this, because it avoids the internation setting issue and works with a wider range of numbers:
Application.Goto ActiveWorkbook.Sheets("sheet2").Cells(8, 3) 'Enter data
ActiveCell.FormulaR1C1 = CDbl(TextBox1)
Private Sub TextBox1_Change()
TextBox1 = Format(TextBox1, "#,###")
End Sub
Which is the right way to go? When I did it with the first code, in the begining it was like this Format(TextBox1, "#,###") The problem was the cell showed a warning asking if I wanted to convert the value to a number. Then I asked how could I store the
textbox value on the cell without being a string and having to convert it to a number. My workmate told me to write it like this: Format(TextBox1, "#")
Then other workmate came and told me that using the VB CDbl function was much better, but now I'm confused.
Thanks