Danny
Danny

Reputation: 89

Format Textbox in vba excel

I have a form that fills textbox with the value in a specific column on the active row. I have one problem, the column is numeric but has the character"-" for e.g 0000-00-000-000 I want the textbox to format as 0000000000000 when the form opens. I use the code below but it doesnt do anything

Private Sub UserForm_Initialize()
Dim r As Long

    r = ActiveCell.Row

    Me.TextBox1.value = Cells(r, 9).value
    TextBox1.Text = Format(TextBox1.Text, "0000000000000")
End Sub

Upvotes: 0

Views: 616

Answers (1)

SeanC
SeanC

Reputation: 15923

replace is the function that will manipulate the string as required.

The simplest way would be to simply remove the dashes by replacing them with an empty string

TextBox1.Text = replace(TextBox1.Text,"-","")

Upvotes: 1

Related Questions