Hi,
I created multiple Textboxes in a UserForm2 based on a row and values from a worksheet.
When a user modify a value in those boxes the format of number is not kept.
I would like to keep the number format when user change the value of some of these textboxes but I really dont know how to capture that event and change the format back to (Format(box.Value, "#,##0.00") .
Here is my code of UserForm2 of how the textboxes are created and value assigned and formating :
Thanks for your help
I created multiple Textboxes in a UserForm2 based on a row and values from a worksheet.
When a user modify a value in those boxes the format of number is not kept.
I would like to keep the number format when user change the value of some of these textboxes but I really dont know how to capture that event and change the format back to (Format(box.Value, "#,##0.00") .
Here is my code of UserForm2 of how the textboxes are created and value assigned and formating :
Code:
Option Explicit
Const CCie = 1
Const PrimeAmt = 2
Const NetAmt = 3
Const StateID = 4
Private Sub UserForm_Initialize()
Dim row As Range
For Each row In ActiveSheet.Rows
If row.Cells(1, CCie).Value = "" Then
Exit For
End If
Call AddBox(row, CCie)
Call AddBox(row, PrimeAmt)
Call AddBox(row, NetAmt)
Call AddBox(row, StateID)
Next row
End Sub
Private Sub AddBox(row, colIndex)
Dim box As MSForms.Control
Const width = 60
Const padWidth = width + 4
Const height = 15
Const padHeight = height + 4
Const topMargin = 80
Const leftMargin = 5
Set box = Me.Controls.Add("Forms.TextBox.1", row.row & colIndex)
box.Left = (colIndex - 1) * padWidth + leftMargin
box.height = height
box.width = width
box.Top = (row.row - 1) * padHeight + topMargin
box.Value = row.Cells(1, colIndex).Value
If colIndex = 2 Or colIndex = 3 Then
box.Value = Format(box.Value, "#,##0.00")
End If
End Sub
Thanks for your help
Last edited: