Format TextBox with 1 code for many Textboxes

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,831
Office Version
  1. 2007
Platform
  1. Windows
Userform has 14 TextBoxes.

This works to show the currency correyly example £12,345.00
VBA Code:
TextBox1.Value = Format(TextBox1.Value, "Currency")

But i dont want to write that to each Textbox so is there a code that will apply that currency format to the TextBoxeas on the userform
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
should use loop throughout textboxes
example:
you have 4 textboxes
so should be
on userform module
VBA Code:
Sub crr()
Dim i As Long
For i = 1 To 4
    Controls("textbox" & i).Value = Format(Controls("textbox" & i).Value, "currency")
    Next i
End Sub
VBA Code:
Private Sub TextBox1_AfterUpdate()
Call crr
End Sub
VBA Code:
Private Sub TextBox2_AfterUpdate()
Call crr
End Sub
 
Upvote 0
This is the same thing but after you enter all of your values in the TextBoxes click on the UserForm an it will update formats so that you don't have to write code for each TextBox_AfterUpdate.
VBA Code:
Private Sub UserForm_Click()
Dim tb
For Each tb In Me.Controls
    If TypeName(tb) = "TextBox" Then
        tb.Value = Format(tb.Value, "Currency")
    End If
Next tb
End Sub
 
Upvote 0
so that you don't have to write code for each TextBox_AfterUpdate.
this is unusual way !
usually will write in textbox and use enter to move next textbox and see the changes instead of waiting to complete writing for all of textboxes to see changes .;)
 
Upvote 0

Forum statistics

Threads
1,224,588
Messages
6,179,743
Members
452,940
Latest member
rootytrip

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