MartinS
Active Member
- Joined
- Jun 17, 2003
- Messages
- 490
- Office Version
- 365
- Platform
- Windows
I have a workbook where, in a summary section, some of the values should be displayed as text using the cell format from the source range.
I have found that using Format doesn't work, i.e.
So Udf_GetFormattedValue(7944808.4,"#,##0.0,;(#,##0.0,)") returns 7,944,808.4, when I'd expect 7,944.8.
I have found that swapping Format for WorksheetFunction.Text works, i.e.
But is there any way without using worksheet functions to return the correctly formatted value from the function?
Many thanks
Martin
I have found that using Format doesn't work, i.e.
VBA Code:
Function Udf_GetFormattedValue(rngCell As Range) As String
Dim strResult As String
strResult = rngCell.Value
If IsEmpty(rngCell) Then
strResult = ""
Else
If StrComp(rngCell.NumberFormat, "General", vbTextCompare) <> 0 Then
strResult = WorksheetFunction.Text(strResult, rngCell.NumberFormat)
End If
End If
Udf_GetFormattedValue = strResult
End Function
I have found that swapping Format for WorksheetFunction.Text works, i.e.
VBA Code:
strResult = WorksheetFunction.Text(strResult, rngCell.NumberFormat)
Many thanks
Martin