Excelで1.20*10^3といった指数表記で記述されたセルの内容を、 1.20×103のような実験などでよく出てくる形に自動的に変換するマクロを作ってみました(と言っても参考ページのをほとんどパクってますが)。
合わせて、1.20*10^3のような表記の文字列を計算して数式にするマクロも作りました。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub Transform() | |
Dim cell As Range | |
For Each cell In Selection | |
cell = Replace(cell, "*", "×") | |
exps = Split(cell, "^") | |
If Not IsEmpty(cell) Then | |
If UBound(exps) = 1 And exps(0) <> "" Then | |
cell = exps(0) & exps(1) | |
cell.Characters(Len(exps(0)) + 1).Font.Superscript = True | |
End If | |
End If | |
Next | |
End Sub | |
Function CalcExp(cell) | |
Dim num As Double | |
exps = Split(cell, "*10^") | |
If Not IsEmpty(cell) Then | |
If UBound(exps) = 1 And exps(0) <> "" Then | |
num = exps(0) * 10 ^ exps(1) | |
End If | |
End If | |
CalcExp = num | |
End Function |
Transformは変換したいセルを選択して実行すればOKです。 CalcExpはCalcExp(A1)みたいな感じでセルを参照してあげて下さい。
Excel質問掲示板(VBA) Re[1: 数字を上付き文字を含んだ指数表示にするには]
を参考にさせて頂きました。
0 件のコメント:
コメントを投稿