変数が数値型かどうかをチェックする( 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 |
実行結果
関連記事
-
日付時刻:文字列から日付・時刻データを取得( DateValue 関数、TimeValue 関数 )
DateValue 関数(文字列から日付データを取得) 【書式】 date_va …
-
文字列:文字列の空白を削除(Trim 関数, LTrim関数, RTrim関数)
Trim 関数・LTrim 関数・RTrim 関数の使い方 【書式】 <先頭と末 …
-
VBA で正規表現を使う(RegExp オブジェクトのプロパティ)
RegExp オブジェクトのプロパティ RegExp オブジェクトの詳細に関して …
-
指定した値を16進数で表記した文字列に変換する(Hex 関数)
Hex 関数 の使い方 【書式】 result = Hex ( expressi …
-
ユーザー定義関数:自動再計算関数の設定(Volatile メソッド)
ユーザー定義関数で、自動再計算を行うかどうかを設定する ワークシート上で使用する …
-
VBA の演算子(論理演算子:And、Eqv、Imp、Not、Or、Xor)
論理演算子 論理演算を行うときに使用する演算子で、以下の 6 種類があります。 …
-
指定した数値を文字列に変換する(Str 関数)
Str 関数 の使い方 Str 関数は、数値・数式を文字列に変換して返す関数です …
-
連想配列(Dictionary オブジェクト)
連想配列 連想配列とは、添字(キー)に文字列を使用することができる配列です。 V …
-
書式を変換(Format 関数)
Format 関数の使い方 【書式】 result = Format ( exp …
-
コレクション(Collection)オブジェクト「連想配列」
コレクション(Collection)オブジェクトの使い方 【書式】 Dim my …