{"id":808,"date":"2016-03-01T07:00:47","date_gmt":"2016-03-01T06:00:47","guid":{"rendered":"http:\/\/axotron.se\/blog\/?p=808"},"modified":"2017-09-12T20:16:15","modified_gmt":"2017-09-12T19:16:15","slug":"excel-vba-function-for-formatting-numbers-with-si-prefixes","status":"publish","type":"post","link":"https:\/\/axotron.se\/blog\/excel-vba-function-for-formatting-numbers-with-si-prefixes\/","title":{"rendered":"Excel VBA functions for formatting numbers using SI prefixes (and back)"},"content":{"rendered":"<p>Excel does not have any built-in way of formatting numbers such that the numbers are displayed in a neatly readable way using SI prefixes, like m for milli (10^-3), k for kilo (10^3), \u00b5 for micro (10^-6) etc. Here I provide a VBA function I wrote to fill this need. In addition, I added support for using the prefix notation of Spice circuit simulators where both m and M are interpreted as milli and Meg has to be used to signify mega. Also, u has to be used instead of \u00b5 to indicate micro in Spice.<\/p>\n<p>As icing on the cake, I also wrote a function to convert the resulting strings back to numbers.<\/p>\n<p>The functions are called FormatPrefix and ValPrefix. Source code with detailed descriptions of the input arguments are shown further down in this post.<\/p>\n<p>Below is a link to an Excel document with the functions built into a VBA module and a worksheet with an example table of values fed to the function to display its output for a large variation of input arguments:<\/p>\n<p><a href=\"http:\/\/axotron.se\/blog\/wp-content\/uploads\/2016\/02\/ExcelPrefixFormattingFunction.xls\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" src=\"http:\/\/axotron.se\/blog\/wp-content\/uploads\/2016\/02\/excel.png\" alt=\"[Excel]\" width=\"24\" height=\"24\" \/> ExcelPrefixFormattingFunction.xls<\/a><\/p>\n<p>Here is a screenshot demonstrating the formatting:<\/p>\n<figure id=\"attachment_823\" aria-describedby=\"caption-attachment-823\" style=\"width: 604px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/axotron.se\/blog\/wp-content\/uploads\/2016\/03\/format_table.png\" rel=\"attachment wp-att-823\"><img loading=\"lazy\" decoding=\"async\" class=\"size-large wp-image-823\" src=\"http:\/\/axotron.se\/blog\/wp-content\/uploads\/2016\/03\/format_table-852x1024.png\" alt=\"Excel table showing the output of FormatPrefix for a large set of input arguments.\" width=\"604\" height=\"726\" srcset=\"https:\/\/axotron.se\/blog\/wp-content\/uploads\/2016\/03\/format_table-852x1024.png 852w, https:\/\/axotron.se\/blog\/wp-content\/uploads\/2016\/03\/format_table-250x300.png 250w, https:\/\/axotron.se\/blog\/wp-content\/uploads\/2016\/03\/format_table-768x923.png 768w, https:\/\/axotron.se\/blog\/wp-content\/uploads\/2016\/03\/format_table.png 967w\" sizes=\"auto, (max-width: 604px) 100vw, 604px\" \/><\/a><figcaption id=\"caption-attachment-823\" class=\"wp-caption-text\">Excel table showing the output of FormatPrefix for a large set of input arguments.<\/figcaption><\/figure>\n<p>The source code is shown below:<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nPublic Function FormatPrefix(value As Double, _\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Optional precision As Integer = 3, _\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Optional blankZero As Boolean = False, _\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Optional space As Boolean = False, _\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Optional spice As Boolean = False) As String\r\n\u00a0\u00a0\u00a0 ' Convert a number to a string, usually with an SI prefix at the end.\r\n\u00a0\u00a0\u00a0 '\r\n\u00a0\u00a0\u00a0 ' Arguments:\r\n\u00a0\u00a0\u00a0 ' value is the value to be converted.\r\n\u00a0\u00a0\u00a0 ' Optional precision argument determines number of significant digits to be printed (default 3).\r\n\u00a0\u00a0\u00a0 ' Optional blankZero argument determines if zero should return the empty string (default false).\r\n\u00a0\u00a0\u00a0 ' Optional space argument determines if a space should be inserted after the number but before\r\n\u00a0\u00a0\u00a0 '\u00a0 a possible prefix (default false).\r\n\u00a0\u00a0\u00a0 ' Optional spice argument determines if Spice prefixes should be used instead of metric ones\r\n\u00a0\u00a0\u00a0 '\u00a0 (default false). The only differences are Meg vs M and u vs \u00b5.\r\n\u00a0\u00a0\u00a0 ' Values above or equal to 1e15 or below 1e-18 are printed using scientific notation without\r\n\u00a0\u00a0\u00a0 ' prefix.\r\n\u00a0\u00a0\u00a0 ' The decimal indicator is always a point, even if the locale says it should be a comma.\r\n\u00a0\u00a0\u00a0 '\r\n\u00a0\u00a0\u00a0 ' Written by Per Magnusson, Axotron, 2016-02-26\r\n\u00a0\u00a0\u00a0 ' This code is public domain and comes without any warranty. Enjoy!\r\n\u00a0\u00a0 \u00a0\r\n\u00a0\u00a0\u00a0 ' Handle the value 0\r\n\u00a0\u00a0\u00a0 If value = 0 Then\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 If blankZero Then\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 FormatPrefix = &quot;&quot;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Else\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 If space Then\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 FormatPrefix = &quot;0 &quot;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Else\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 FormatPrefix = &quot;0&quot;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 End If\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 End If\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Exit Function\r\n\u00a0\u00a0\u00a0 End If\r\n\u00a0\u00a0 \u00a0\r\n\u00a0\u00a0\u00a0 ' Handle negative numbers\r\n\u00a0\u00a0\u00a0 sign = 1\r\n\u00a0\u00a0\u00a0 If value &lt; 0 Then \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 sign = -1 ' store the sign \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 value = -value ' make value positive until later \u00a0\u00a0\u00a0 End If \u00a0\u00a0 \u00a0 \u00a0\u00a0\u00a0 ' Calculate exponent and mantissa \u00a0\u00a0\u00a0 exponent = Int(Log(value) \/ Log(10#)) \u00a0\u00a0\u00a0 mantissa = Round(value \/ (10 ^ exponent), precision - 1) \u00a0\u00a0\u00a0 If mantissa &gt;= 10 Then\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ' Handle the case where the mantissa is rounded up to 10\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 exponent = exponent + 1\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 mantissa = mantissa \/ 10\r\n\u00a0\u00a0\u00a0 End If\r\n\u00a0\u00a0\u00a0 exponent3 = 3 * Int(exponent \/ 3) 'exponent rounded down to nearest multiple of 3\r\n\u00a0\u00a0 \u00a0\r\n\u00a0\u00a0\u00a0 ' Find the right prefix\r\n\u00a0\u00a0\u00a0 If exponent &gt;= 15 Then\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ' Too big to represent with the supported prefixes, use scientific notation\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 prefix = &quot;sci&quot;\r\n\u00a0\u00a0\u00a0 ElseIf exponent &gt;= 12 Then\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 prefix = &quot;T&quot;\r\n\u00a0\u00a0\u00a0 ElseIf exponent &gt;= 9 Then\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 prefix = &quot;G&quot;\r\n\u00a0\u00a0\u00a0 ElseIf exponent &gt;= 6 Then\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 If spice Then\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 prefix = &quot;Meg&quot;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Else\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 prefix = &quot;M&quot;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 End If\r\n\u00a0\u00a0\u00a0 ElseIf exponent &gt;= 3 Then\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 prefix = &quot;k&quot;\r\n\u00a0\u00a0\u00a0 ElseIf exponent &gt;= 0 Then\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 prefix = &quot;&quot;\r\n\u00a0\u00a0\u00a0 ElseIf exponent &gt;= -3 Then\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 prefix = &quot;m&quot;\r\n\u00a0\u00a0\u00a0 ElseIf exponent &gt;= -6 Then\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 If spice Then\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 prefix = &quot;u&quot;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Else\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 prefix = &quot;\u00b5&quot;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 End If\r\n\u00a0\u00a0\u00a0 ElseIf exponent &gt;= -9 Then\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 prefix = &quot;n&quot;\r\n\u00a0\u00a0\u00a0 ElseIf exponent &gt;= -12 Then\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 prefix = &quot;p&quot;\r\n\u00a0\u00a0\u00a0 ElseIf exponent &gt;= -15 Then\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 prefix = &quot;f&quot;\r\n\u00a0\u00a0\u00a0 ElseIf exponent &gt;= -18 Then\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 prefix = &quot;a&quot;\r\n\u00a0\u00a0\u00a0 Else\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ' Too small to represent with the supported prefixes, use scientific notation\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 prefix = &quot;sci&quot;\r\n\u00a0\u00a0\u00a0 End If\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\r\n\u00a0\u00a0\u00a0 If prefix = &quot;sci&quot; Then\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ' Use scientific notation\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 formatStr = &quot;0&quot;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 If precision &gt; 1 Then\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 formatStr = formatStr &amp; &quot;.&quot;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 For ii = 1 To precision - 1\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 formatStr = formatStr &amp; &quot;0&quot;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Next\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 End If\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 formatStr = formatStr &amp; &quot;e-0&quot;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 prefix = &quot;&quot;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 value = sign * mantissa * 10 ^ exponent\r\n\u00a0\u00a0\u00a0 Else\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 decimals = precision - (exponent - exponent3) - 1\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 If decimals &gt; 0 Then\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 formatStr = &quot;0.&quot;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 For ii = 1 To decimals\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 formatStr = formatStr &amp; &quot;0&quot;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Next\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Else\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 formatStr = &quot;0&quot;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 End If\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 value = sign * mantissa * 10 ^ (exponent - exponent3)\r\n\u00a0\u00a0\u00a0 End If\r\n\u00a0\u00a0\u00a0 optSpace = &quot;&quot;\r\n\u00a0\u00a0\u00a0 If space Then\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 optSpace = &quot; &quot;\r\n\u00a0\u00a0\u00a0 End If\r\n\u00a0\u00a0\u00a0 FormatPrefix = Replace(Format(value, formatStr) &amp; optSpace &amp; prefix, &quot;,&quot;, &quot;.&quot;)\r\n\u00a0\u00a0\u00a0 'FormatPrefix = formatStr &amp; optSpace &amp; prefix\r\nEnd Function\r\n\r\n\r\n\r\nPublic Function ValPrefix(str As String) As Double\r\n\u00a0\u00a0\u00a0 ' Convert a number formatted as a string using FormatPrefix() back to a number.\r\n\u00a0\u00a0\u00a0 '\r\n\u00a0\u00a0\u00a0 ' Arguments:\r\n\u00a0\u00a0\u00a0 ' str is the string to be converted\r\n\u00a0\u00a0\u00a0 ' Error checking is very limited.\r\n\u00a0\u00a0\u00a0 '\r\n\u00a0\u00a0\u00a0 ' Written by Per Magnusson, Axotron, 2016-02-26\r\n\u00a0\u00a0\u00a0 ' This code is public domain and comes without any warranty. Enjoy!\r\n\u00a0\u00a0 \u00a0\r\n\u00a0\u00a0\u00a0 exponent = 0\r\n\u00a0\u00a0\u00a0 prefix = &quot;&quot;\r\n\u00a0\u00a0\u00a0 strlen = Len(str)\r\n\u00a0\u00a0 \u00a0\r\n\u00a0\u00a0\u00a0 If StrComp(Right(str, 1), &quot;A&quot;) &gt;= 0 Then\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ' There is a letter at the end of the value\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ii = 1\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 While StrComp(Mid(str, strlen - ii, 1), &quot;A&quot;) &gt;= 0\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ii = ii + 1\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Wend\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 prefix = Mid(str, strlen - ii + 1)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Select Case prefix\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Case &quot;T&quot;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 exponent = 12\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Case &quot;G&quot;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 exponent = 9\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Case &quot;M&quot;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 exponent = 6\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Case &quot;Meg&quot;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 exponent = 6\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Case &quot;k&quot;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 exponent = 3\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Case &quot;m&quot;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 exponent = -3\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Case &quot;u&quot;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 exponent = -6\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Case &quot;\u00b5&quot;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 exponent = -6\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Case &quot;n&quot;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 exponent = -9\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Case &quot;p&quot;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 exponent = -12\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Case &quot;f&quot;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 exponent = -15\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Case &quot;a&quot;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 exponent = -18\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Case Else\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ' Error, handle it somehow?\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ValPrefix = &quot;Prefix error&quot;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Exit Function\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 End Select\r\n\u00a0\u00a0\u00a0 End If\r\n\u00a0\u00a0\u00a0 ValPrefix = Val(str) * 10 ^ exponent\r\n\u00a0\u00a0 \u00a0\r\nEnd Function\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Excel does not have any built-in way of formatting numbers such that the numbers are displayed in a neatly readable way using SI prefixes, like m for milli (10^-3), k for kilo (10^3), \u00b5 for micro (10^-6) etc. Here I provide a VBA function I wrote to fill this need. In addition, I added support &hellip; <a href=\"https:\/\/axotron.se\/blog\/excel-vba-function-for-formatting-numbers-with-si-prefixes\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Excel VBA functions for formatting numbers using SI prefixes (and back)<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,12],"tags":[],"class_list":["post-808","post","type-post","status-publish","format-standard","hentry","category-electronics","category-pc"],"_links":{"self":[{"href":"https:\/\/axotron.se\/blog\/wp-json\/wp\/v2\/posts\/808","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/axotron.se\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/axotron.se\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/axotron.se\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/axotron.se\/blog\/wp-json\/wp\/v2\/comments?post=808"}],"version-history":[{"count":19,"href":"https:\/\/axotron.se\/blog\/wp-json\/wp\/v2\/posts\/808\/revisions"}],"predecessor-version":[{"id":1351,"href":"https:\/\/axotron.se\/blog\/wp-json\/wp\/v2\/posts\/808\/revisions\/1351"}],"wp:attachment":[{"href":"https:\/\/axotron.se\/blog\/wp-json\/wp\/v2\/media?parent=808"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/axotron.se\/blog\/wp-json\/wp\/v2\/categories?post=808"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/axotron.se\/blog\/wp-json\/wp\/v2\/tags?post=808"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}