変数が日付型かどうかをチェックする( IsDate 関数 )
IsDate 関数の使い方
【書式】
result = IsDate( expression )
【引数・戻り値】
- expression ・・・ 調べる変数や式
- result ・・・ 引数 expression が、日付型( Date 型 )に変換できる(日付として解釈)できるかどうかを調べた結果(ブール型:日付型に変換可能な場合は、True / それ以外の場合は、False )。
IsDate 関数の使用例
サンプル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 |
Sub Sample_isdate() '以下、True を返す Debug.Print IsDate(#4/1/2015#) Debug.Print IsDate(#6/21/2013 7:02:23 PM#) Debug.Print IsDate(DateSerial(2012, 1, 1)) Debug.Print IsDate(Now) Debug.Print IsDate("2000,4,11") Debug.Print IsDate("1:20") Debug.Print IsDate("2005/9/1 11:30 AM") Debug.Print IsDate("昭和60年7月20日 1時30分") '以下、False を返す Debug.Print IsDate("おはよう!") Debug.Print IsDate(42005) Debug.Print IsDate(0) Debug.Print IsDate("") Debug.Print IsDate(Empty) Debug.Print IsDate(Null) End Sub |
実行結果
関連記事
-
-
指定した文字列を数値に変換する(Val 関数)
Val 関数 の使い方 Val 関数は、指定した文字列に含まれる数字を数値として …
-
-
出力位置、書き込み位置を設定(Tab 関数)
出力位置、書き込み位置を設定 Tab 関数 は、Print メソッド、または P …
-
-
文字列:文字列左から指定文字数取得(Left 関数,LeftB 関数)
Left 関数・LeftB 関数 の使い方 【書式】 result_left = …
-
-
書式を変換(Format 関数)
Format 関数の使い方 【書式】 result = Format ( exp …
-
-
対象のオブジェクトをクリアする(Clear メソッド)
Clear メソッド 対象となるオブジェクト全体をクリアします。Range オブ …
-
-
Array 関数(バリアント型の配列を作成)
Array 関数の使い方 【書式】 myArray = Array ( elem …
-
-
文字列:文字を指定数並べた文字列を返す(String 関数)
String 関数 【書式】 result = String ( number, …
-
-
日付時刻:数値から日付・時刻データを取得( DateSerial 関数、TimeSerial 関数 )
DateSerial 関数(数値を使って日付データを取得) 【書式】 date …
-
-
Math 関数( Abs,Atn,Cos,Exp,Log,Rnd,Sgn,Sin,Sqr,Tan )
Abs 関数 【書式】 value = Abs ( number ) 【引数・戻 …
-
-
xlFileFormat 列挙型
xlFileFormat 列挙型 Workbook.SaveAs メソッド の引 …