Add Currency format

josros60

Well-known Member
Joined
Jun 27, 2010
Messages
786
Office Version
  1. 365
Hi,
I have a code for listbox with textboxes.

how can I format the box to $ currency by adding this line of code to each box that has dollar amount, I would like to add this line of code:

Code:
" & Format(Range("E").Value, "$#,##0.00;($#,##0.00)")

to this code: (Bold and red colour)

Code:
Private Sub ListBox_Results_Click()'Go to selection on sheet when result is clicked

Dim strAddress As String
Dim l As Long


    For l = 0 To ListBox_Results.ListCount
        If ListBox_Results.Selected(l) = True Then
            strAddress = ListBox_Results.List(l, 1)
            ActiveSheet.Range(strAddress).Select
            'Populate textboxes with results
            With ActiveSheet
[COLOR=#ff0000][B]                f_FindAll.TextBox_Results1.Value = .Cells(.Range(strAddress).Row, 5).Value[/B][/COLOR]
[COLOR=#ff0000][B]                f_FindAll.TextBox_Results2.Value = .Cells(.Range(strAddress).Row, 4).Value[/B][/COLOR]
[COLOR=#ff0000][B]                f_FindAll.TextBox_Results3.Value = .Cells(.Range(strAddress).Row, 1).Value[/B][/COLOR]
            End With
            GoTo EndLoop
        End If
    Next l


EndLoop:

thanks.
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Code:
f_FindAll.TextBox_Results1.Value = Format(.Cells(.Range(strAddress).Row, 5).Value, "$#,##0.00;($#,##0.00)")
 
Upvote 0
Thank you so much, worked perfectly.
 
Last edited by a moderator:
Upvote 0
I have a similar problem. I have a userform that displays several cells of a record that in the worksheet are formatted as $25.12 for example. On the form the textbox the data does not appear as currency. I have succeeded in getting it to show as currency after altering the figure in the form textbox using the following code:

VBA Code:
Private Sub TextBox6_AfterUpdate()
    'format new input value as Currency
    TextBox6.Value = Format(TextBox6.Value, "$#,##0.00")
End Sub
But I also want the value to appear as currency when it is first loaded from the worksheet into the form textbox .

Help will be appreciated.
 
Upvote 0
Sorry for delay, only just seen this. The point is to understand that the worksheet cell has two distinct elements, the value and the format. When another cell refers to that cell it may pick up the formatting as well, but when passing the value into a text field, you aren't getting that format, only the value

So you need to apply the format part when you capture the cell value and load it into the form first time. To confirm how, I'd need to see the code you use to load the form

This might come with a problem, in that the value in a textbox is now no longer a number, but potentially only readable as a text string. We'll worry about that later though
 
Upvote 0
Thanks. I understand and will give it a try. If I fail I will make another post here.
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,194
Members
452,616
Latest member
intern444

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