Excel / 0かEmptyか判別する方法
なぜか、Excelでは空セルと0は同じと扱う。
awkもそんな仕様だけどね。
テストプログラム
Sub test() Debug.Print vbCrLf & "test start!!" Debug.Print "A1=" & Range("A1").Value Debug.Print "A2=" & Range("A2").Value 'NGな現象 If Range("A1").Value = Range("A2").Value Then Debug.Print "バリアント型比較 同じと判定" Else Debug.Print "バリアント型比較 ちがうと判定" End If '文字にキャストする If CStr(Range("A1").Value) = CStr(Range("A2").Value) Then Debug.Print "文字型比較 同じと判定" Else Debug.Print "文字型比較 ちがうと判定" End If End Sub
結果
test start!! A1= A2=0 バリアント型比較 同じと判定 文字型比較 ちがうと判定