0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Excel VBAエラー逆引き① 【実行時エラー ‘13’: 型が一致しません。】

Last updated at Posted at 2025-07-14

【実行時エラー ‘13’: 型が一致しません。】の対処法です。

image.png

実行時エラー ‘13’:
型が一致しません。

チェック 1 - Level 0 -

型の違う変数に値を代入してませんか?

VBAの変数には型があります。「文字列ですか?」「整数ですか?」「小数ですか?」この型を間違って代入するとこのエラーが表示されます。

Sub SampleError1_1()
    Dim Something As Integer '『Somethingは整数です』
    Something = "文字列" '文字列を代入!!ここでエラー
End Sub

チェック 2 - Level 1 -

Excelセルのデータ型は大丈夫ですか?

上の例では間違いが明白ですが、Excelセルの値を代入する時は気づきにくい事があります。特にExcelシート上の大量のデータを処理する際、想定外の値が記入されていてエラーが起きる場合があります。

ここでは"A1"セルに整数、"B1"セルに文字列が記入されています。

image.png

Sub SampleError1_2()
    Dim Something As Integer '『Somethingは整数です』
    Something = ActiveSheet.Range("A1").Value '"A1"は整数なので問題無し
    Something = ActiveSheet.Range("B1").Value '"B1"は文字列!!ここでエラー
End Sub
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?