在域中的数字图片开关中(图片项中)并没有科学记数法,简单的检查方法中是在表格中,使用公式命令点数字格式,就7种,粘贴函数中也没有相应的转换函数。 以下是VBA代码通过运行该宏可以取得相应科学记数法:(供参考) (有两种途径,一是在选定数字后插入,二是将原有数据删掉后转换可根据需要修改,但该代码只针对正数如果需要使用负数,可适合修改代码或者选择时“-” 号不选定并采用途径二) Sub Kjf()
Dim Sel As Byte, MyValue As Single, Myrange As Range, i As Byte, Dw As Byte
Set Myrange = Selection.Range
With Myrange
Sel = Len(Myrange)
If Myrange Like "#*.#*" = True Then
For i = 2 To Sel
If Mid(Myrange, i, 1) = "." Then Dw = i
If Mid(Myrange, i, 1) Like "#" = True Or Mid(Myrange, i, 1) = "." Then
Else
MsgBox "无效数据!"
Exit Sub
End If
Next
MyValue = Selection.Calculate / (10 ^ (Dw - 2))
Selection.Delete
Selection.InsertAfter MyValue & "E+" & (Dw - 2)
'Selection.InsertAfter "=" & MyValue & "E+" & (Dw - 2)
Exit Sub
End If
If Myrange Like "##*" = True Then
For i = 2 To Sel
If Mid(Myrange, i, 1) Like "#" = False Then MsgBox "无效数据!": Exit Sub
Next
MyValue = Selection.Calculate / (10 ^ (Sel - 1))
Selection.Delete
Selection.InsertAfter MyValue & "E+" & (Sel - 1)
'Selection.InsertAfter "=" & MyValue & "E+" & (Sel - 1)
Exit Sub
End If
End With
End Sub |