View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Sam Wilson Sam Wilson is offline
external usenet poster
 
Posts: 523
Default Representing numbers with K, M, G sufix using a macro

You'll have to reverse the order of those ifs...

2,000,000,000,000 mod 1E12 = 0 so result = 2T
2,000,000,000,000 mod 1E9 = 0 so result = 2000G
etc.

Sam

"BSc Chem Eng Rick" wrote:

Function NumSuffix(MyNum as Long) as String
Dim Result as String
if MyNum Mod 1E12 = 0 then Result = CStr(Mynum/1E12) & " T"
if MyNum Mod 1E9 = 0 then Result = CStr(Mynum/1E9) & " G"
if MyNum Mod 1E6 = 0 then Result = CStr(Mynum/1E6) & " M"
if MyNum Mod 1E3 = 0 then Result = CStr(Mynum/1E3) & " K"
NumSuffix = Result
End Function
--
If this helps, please click "Yes"
<<<<<<<<<<<<


"Farooq Sheri" wrote:

I need help with code to convert a number, for example 2000000, into 2 M or
2000000000 into 2 G etc.

Thanks.

Farooq