変数が数値型かどうかをチェックする( IsNumeric 関数 )
IsNumeric 関数の使い方
【書式】
result = IsNumeric ( expression )
【引数・戻り値】
- expression ・・・ 調べる変数や式
- result ・・・ 引数 expression が、数値として扱えるかどうかを調べた結果(ブール型:数値として扱える場合は、True / それ以外の場合は、False )。
IsNumeric 関数の使用例
サンプルVBAソース
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
Sub Sample_isnumeric() '以下、True を返す Debug.Print IsNumeric(42005) Debug.Print IsNumeric(-42.005) Debug.Print IsNumeric(0) Debug.Print IsNumeric("234.567") Debug.Print IsNumeric(12 ^ 7) Debug.Print IsNumeric(10 / 3) Debug.Print IsNumeric(Empty) Debug.Print IsNumeric("2000,4,11") Debug.Print IsNumeric(Sqr(10)) Debug.Print IsNumeric(Int(Rnd * 6) + 1) Debug.Print '以下、False を返す Debug.Print IsNumeric(#4/1/2015#) Debug.Print IsNumeric(#6/21/2013 7:02:23 PM#) Debug.Print IsNumeric(DateSerial(2012, 1, 1)) Debug.Print IsNumeric(Now) Debug.Print IsNumeric("1:20") Debug.Print IsNumeric("2005/9/1 11:30 AM") Debug.Print IsNumeric("昭和60年7月20日 1時30分") Debug.Print IsNumeric("おはよう!") Debug.Print IsNumeric("") Debug.Print IsNumeric(Null) End Sub |
実行結果
関連記事
-
-
ユーザー定義関数:セルを取得する(ThisCell プロパティ)
入力されたセルを取得する ワークシート上で使用する Function プロシージ …
-
-
Math 関数( Abs,Atn,Cos,Exp,Log,Rnd,Sgn,Sin,Sqr,Tan )
Abs 関数 【書式】 value = Abs ( number ) 【引数・戻 …
-
-
配列(宣言・要素数の変更について)
配列の宣言 【書式】※ 配列の宣言 <Type 型の静的配列(固定長配列)の宣言 …
-
-
変数が日付型かどうかをチェックする( IsDate 関数 )
IsDate 関数の使い方 【書式】 result = IsDate( expr …
-
-
日付時刻:時・分・秒を取得(Hour、Minute、Second 関数)
日付時刻から時・分・秒を取得する関数 【書式】 time_hour = Hour …
-
-
カレントフォルダ(CurDir 関数、ChDir ステートメント、ChDrive ステートメント)
カレントフォルダ カレントフォルダとは、ブックを開いたり保存するときに既定で参照 …
-
-
日付時刻:日付から曜日を取得( Weekday 関数、WeekdayName 関数 )
Weekday 関数(日付から曜日を表す数値を返す)の使い方 【書式】 week …
-
-
オートシェイプの種類を表す定数(MsoAutoShapeType 列挙型)
MsoAutoShapeType 列挙型 オートシェイプオブジェクトの図形の種類 …
-
-
VBA の演算子(文字連結演算子:& 演算子 + 演算子)
文字連結演算子 文字連結演算子は、文字列の連結を行うときに使用する演算子で、「& …
-
-
変数のデータ型・宣言(Dim ステートメント)
変数の宣言 一般的な方法 【書式】 Dim varname [ As type, …