0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

なぜExcelの指数はわかりにくい表現をするのか

Last updated at Posted at 2022-06-21

概要

Excelで指数表示を設定すると、以下のように Eを付与した指数表示をします。
1.E-02 は、1/10/10 で 0.001 、 1.E-04 は 1/10/10/10/10 で 0.0001 という規則があります。
ただ、電気系からすると 1.E-04 なんて、わかりにくい!!!
100.0E-06 と表現した方が、わかりやすい。
直感で 100μ というのもわかります。

指数表示    数値表示
1.E+00     1.0
1.E-01     0.1
1.E-02     0.01
1.E-03     0.001
1.E-04     0.0001
1.E-05     0.00001
1.E-06     0.000001
1.E-07     0.0000001
1.E-08     0.00000001
1.E-09     0.000000001
1.E-10     0.0000000001
1.E-11     0.00000000001

そこで、今回は指数表現を「係数3つ飛ばし」と「SI接続記号単位」で出力する Funcion 関数を作りました。

指数表現の係数は3つ飛ばしで表示

指数表示    係数3つ飛ばし表示
1.E+00     1.0
1.E-01     100.0E-03
1.E-02     10.0E-03
1.E-03     1.0E-03
1.E-04     100.0E-06
1.E-05     10.0E-06
1.E-06     1.0E-06
1.E-07     100.0E-09
1.E-08     10.0E-09
1.E-09     1.0E-09
1.E-10     100.0E-12
1.E-11   10.0E-12

ついでにSI接続記号単位で表現

指数表示    SI接続記号単位表示
1.E+00     1.0
1.E-01     100.0m
1.E-02     10.0m
1.E-03     1.0m
1.E-04     100.0u
1.E-05     10.0u
1.E-06     1.0u
1.E-07     100.0n
1.E-08     10.0n
1.E-09     1.0n
1.E-10     100.0p
1.E-11   10.0p

Excel VBA Function ExpUnit

これは、SI接続記号単位で表示する関数です。
Frac = "0.0" を選択すると戻り値は少数桁1位になります。

Function ExpUnit
 Function ExpUnit(num As Double) As String
    Dim Frac As String
    
  ' Frac = "0.000"
    Frac = "0.0"
    
    ExpUnit = Format(num, Frac)
    If (Left(ExpUnit, 1) <> "0") Then
        Exit Function
    End If
    
    num = num * 1000
    ExpUnit = Format(num, Frac)
    If (Left(ExpUnit, 1) <> "0") Then
        ExpUnit = ExpUnit + "m"
        Exit Function
    End If
    
    num = num * 1000
    ExpUnit = Format(num, Frac)
    If (Left(ExpUnit, 1) <> "0") Then
        ExpUnit = ExpUnit + "u"
        Exit Function
    End If
    
    num = num * 1000
    ExpUnit = Format(num, Frac)
    If (Left(ExpUnit, 1) <> "0") Then
        ExpUnit = ExpUnit + "n"
        Exit Function
    End If
   
    num = num * 1000
    ExpUnit = Format(num, Frac)
    If (Left(ExpUnit, 1) <> "0") Then
        ExpUnit = ExpUnit + "p"
        Exit Function
    End If

 End Function

Excel VBA Function ExpUnitE

これは、係数を3飛ばしで表現します。
Frac = "0.0" を選択すると戻り値は少数桁1位になります。

Function ExpUnitE
 Function ExpUnitE(num As Double) As String
    Dim Frac As String
    
  ' Frac = "0.000"
    Frac = "0.0"
    
    ExpUnitE = Format(num, Frac)
    If (Left(ExpUnitE, 1) <> "0") Then
        Exit Function
    End If
    
    num = num * 1000
    ExpUnitE = Format(num, Frac)
    If (Left(ExpUnitE, 1) <> "0") Then
        ExpUnitE = ExpUnitE + "E-03"
        Exit Function
    End If
    
    num = num * 1000
    ExpUnitE = Format(num, Frac)
    If (Left(ExpUnitE, 1) <> "0") Then
        ExpUnitE = ExpUnitE + "E-06"
        Exit Function
    End If
    
    num = num * 1000
    ExpUnitE = Format(num, Frac)
    If (Left(ExpUnitE, 1) <> "0") Then
        ExpUnitE = ExpUnitE + "E-09"
        Exit Function
    End If
   
    num = num * 1000
    ExpUnitE = Format(num, Frac)
    If (Left(ExpUnitE, 1) <> "0") Then
        ExpUnitE = ExpUnitE + "E-12"
        Exit Function
    End If

 End Function

使い方

モジュールにmodule1を用意して、Function ExpUnit()とFunction ExpUnitE()をコピペします。
module.png

セルに = expunit(b1) と記載すればすぐに使えます。
cell.png

ExpUnit()を使うと、m u n p のSI接続記号単位で表示します。
unit.png

ExpUnitE()を使うと、係数を3飛ばしで表現します。
unitE.png

最後に

値が文字になって再利用できないのがちょっとアレですが、SI単位表示や、
係数3飛ばし表示ができるようになりますのでちょっとしたところで便利に使えるかと思います。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?