B
Brian Miller
I'm using vba within excel and based upon whether a cell contains data, any
kind of data, I want to perform an action. If the cell has string data the
implicit conditional returns a type mismatch and if the cell has numeric data
the conditional behaves as expected. The result can be duplicated and
generalized and produces similar results in VBA and in VBScript. If Not
IsNull() doesn't seem to work either. Any suggestions would be appreciated.
Thanks,
Brian
This is a VBA script that produces the type mismatch:
Sub Main()
subTestValues
Worksheets(1).Range("A1").Value = 1
Worksheets(1).Range("A5").Value = 5
subTestValues
Worksheets(1).Range("A1").Value = "string"
Worksheets(1).Range("A5").Value = 5
subTestValues
End Sub
Sub subTestValues()
If Range("A1") Or Range("A5") Then 'Using the Cells property produces
the same result.
subMsg ("Either A1 or A5 has a value.")
Else
subMsg ("Neither A1 or A5 has a value.")
End If
End Sub
Sub subMsg(strText As String)
MsgBox strText
End Sub
kind of data, I want to perform an action. If the cell has string data the
implicit conditional returns a type mismatch and if the cell has numeric data
the conditional behaves as expected. The result can be duplicated and
generalized and produces similar results in VBA and in VBScript. If Not
IsNull() doesn't seem to work either. Any suggestions would be appreciated.
Thanks,
Brian
This is a VBA script that produces the type mismatch:
Sub Main()
subTestValues
Worksheets(1).Range("A1").Value = 1
Worksheets(1).Range("A5").Value = 5
subTestValues
Worksheets(1).Range("A1").Value = "string"
Worksheets(1).Range("A5").Value = 5
subTestValues
End Sub
Sub subTestValues()
If Range("A1") Or Range("A5") Then 'Using the Cells property produces
the same result.
subMsg ("Either A1 or A5 has a value.")
Else
subMsg ("Neither A1 or A5 has a value.")
End If
End Sub
Sub subMsg(strText As String)
MsgBox strText
End Sub