IsNumeric 語法說明
IsNumeric 函數會檢查輸入的變數是否能轉為數字,並返回
布林值
(TRUE 或 FALSE)。如果可以轉為數字,回傳 True; 否則,回傳 False
IsNumeric( variable )
備註:變數(variable)類型可以是”字串”或是”數字”
dVariable = DateSerial(2022, 1, 16)
text1 = "variable值:" & variable & vbCrLf & "IsNumeric 函數回傳:" & IsNumeric(variable)
text2 = "dVariable值:" & dVariable & vbCrLf & "IsNumeric 函數回傳:" & IsNumeric(dVariable)
MsgBox text1 & vbCrLf & vbCrLf & text2
End Sub
variable = "10:00:00 AM"
tVariable = TimeSerial(10, 0, 0)
cellVariable = ActiveWorkbook.Sheets(1).Cells(1, 1)
text1 = "variable值:" & variable & vbCrLf & "IsNumeric 函數回傳:" & IsNumeric(variable)
text2 = "tVariable值:" & tVariable & vbCrLf & "IsNumeric 函數回傳:" & IsNumeric(tVariable)
text3 = "cellVariable值:" & cellVariable & vbCrLf & "IsNumeric 函數回傳:" & IsNumeric(cellVariable)
MsgBox text1 & vbCrLf & vbCrLf & text2 & vbCrLf & vbCrLf & text3
End Sub
bl = Application.WorksheetFunction.IsNumber(variable)
MsgBox "variable值:" & variable & vbCrLf & "IsNumber 函數回傳:" & bl
End Sub