変数が日付型かどうかをチェックする( 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 |
実行結果
関連記事
-
-
四捨五入・切り上げ・切り捨て・丸め(Round 関数 他)
Round 関数(丸め)の使い方 【書式】 value = Round ( ex …
-
-
日付時刻:日付・時刻の間隔を取得( DateDiff 関数 )
DateDiff 関数の使い方 【書式】 result = DateDiff ( …
-
-
文字列:文字列左から指定文字数取得(Left 関数,LeftB 関数)
Left 関数・LeftB 関数 の使い方 【書式】 result_left = …
-
-
文字列:指定した文字の文字コードを取得する(Asc 関数)
Asc 関数 【書式】 result = Asc ( string ) 引数・戻 …
-
-
VBA の演算子(比較演算子)
比較演算子 比較演算子による演算の結果は「真」の場合は「True」、「偽」の場合 …
-
-
インプットボックスを表示する(InputBox関数・InputBoxメソッド)
「InputBox関数」と「InputBoxメソッド」の違い 「InputBox …
-
-
VBA の演算子(文字連結演算子:& 演算子 + 演算子)
文字連結演算子 文字連結演算子は、文字列の連結を行うときに使用する演算子で、「& …
-
-
文字列:文字列右から指定文字数取得(Right 関数,RightB 関数)
Right 関数・RightB 関数 の使い方 【書式】 result_righ …
-
-
ある数値が、複数の範囲のどの範囲に含まれるかを示す文字列を返す(Partition 関数)
Partition 関数 の使い方 Partition 関数は、ある数値が、区切 …
-
-
xlFileFormat 列挙型
xlFileFormat 列挙型 Workbook.SaveAs メソッド の引 …
