VBA "Scientific" non-standard number format

Viewed 169

For reasons obscure (I need to match some formatting used in an ancient Fortran code) I need to output from Excel using VBA (to a text file) some numbers in non-standard scientific notation.

For example if x = 6000000

normal VBA:

  mystring = Format(x, "0.000E+00")

produces

  "6.000E+06"

I need a way of producing

  "0.600E+07"

instead. I can't figure out a way of doing this using Format functions. Is this possible?

1 Answers

This should do it:

Dim x As Double
    x = 6000000
Dim myString As String
myString = "0" & VBA.Format(x, ".0000E+00")
Debug.Print myString
Related