Returning two decimal places

nayone

New Member
Joined
Aug 2, 2006
Messages
29
Hi I have a function in a workbook that reformats a number, taking out decimal place & replacing it with a comma:

MsgBox ReformatNumber((Sheet1.Cells(1, 1).Value))
& the function :
Private Function ReformatNumber(ByVal Num As Single) As String
ReformatNumber = Replace(Num, ".", ",")
End Function

now this works fine but I am trying to add zeros to the end so if a user enters 1 or 1.2 we get 1,00 & 1,20 not 1, & 1,2 as currently
I have tried Mid(Num, Trim(Len(Num)) -2 1, 1) = "." to identify items & then add zeros but the 'len' command always returns 4? within the function for any length of text??

any pointers as this ones in got me

thx

Alex
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Works fine thx very much

Had got round it with

If Left(Right(Num, 3), 1) = "." Then
ReformatNumber = Replace(Num, ".", ",")
ElseIf Left(Right(Num, 2), 1) = "." Then
ReformatNumber = Replace(Num, ".", ",") & "0"
Else
ReformatNumber = Num & "," & "00"
'End If

But your code is much neater, thx very much

Alex
 
Upvote 0

Forum statistics

Threads
1,215,696
Messages
6,126,267
Members
449,308
Latest member
VerifiedBleachersAttendee

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