Macro for Format Labels

jdcar

New Member
Joined
Oct 9, 2021
Messages
17
Office Version
  1. 2016
Platform
  1. Windows
Hello everyone,

I have a userform that have a lot of labels to show the currency values.
For that I used the code below:

Private Sub UserForm_Initialize()
Dim xp, As Double
xp = Val(xp)
xp = CDbl(xp)
lbl1.Caption = xp
lbl2.Caption = xp
lbl3.Caption = xp
xp = Sheets("sheet1").Range("A21")
xp = Sheets("sheet1").Range("B21")
xp = Sheets("sheet1").Range("C21")
lbl1.Caption = Format(xp, "#,##0.00 €")
lbl2.Caption = Format(xp, "#,##0.00 €")
lbl3.Caption = Format(xp, "#,##0.00 €")

I wound like to have a macro to simplify the code. I use macro below but didn't worked. Is it possible to agregate all, with the same formats on the labels' values?

Sub FormatValue()
With UserForm3
ary = Array(.lbl1, .lbl2, .lbl3)
For i = 0 To UBound(ary)
ary(i).Caption = Format(i, "#,##0.00 €")
Next i
End With
End Sub

I would be very grateful for the help you can give to solve this problem. Many thanks
 
As Initialize gets quite big, is there any way to simplify it, for example in a macro if possible
 
Upvote 0

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Hi Mr Dante
Made some adjustments between the example and my project, it worked perfectly. Thank you very much.
SOLVED
What didn't work was trying to use the initialize code in a macro, as it gives an error in controls.
will there be a possibility of a macro instead of using it in initialize?
Thank you
Carlos
 
Upvote 0

Forum statistics

Threads
1,215,106
Messages
6,123,123
Members
449,096
Latest member
provoking

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