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

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
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,107
Messages
6,123,126
Members
449,097
Latest member
mlckr

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