Type mismatch error

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I see I'm not the only one with type mismatch problems
I'm sure it's really simple but I have a piece of code where the only undefined element is the name of a function the sub calls at the end. As far as I know this doesn't need to be dimensioned so what am I doing wrong? Here is my code:

Sub bearing(
Dim ABdeg, ABmin, ABsec, XYdeg, XYmin, XYsec As Doubl

'Name WCB cell
ABdeg = Cells(11, "B"
ABmin = Cells(11, "C"
ABsec = Cells(11, "D"
XYdeg = Cells(12, "B"
XYmin = Cells(12, "C"
XYsec = Cells(12, "D"

If ABdeg = " " Or ABmin = " " Or ABsec = " " Or XYdeg = " " Or XYmin = " " Or XYsec = " " The
Call misclosur
End I

End Sub
 
Hi
several things
1. You only have defined the last variable (XYSec) as double, all other
variables are defined as variants
2. You're testing for a Space. Though this won't throw an error for the
variant variables it does for XYSec

So the following line would work
If ABdeg = " " Or ABmin = " " Or ABsec = " " Or XYdeg = " " Or XYmin =
" " Or XYsec = 0 Then

Though I'm quite sure you want to replace the spaces either with "" or
defined all variables as doubles and test them for 0
 
your DIM is wrong,. As you have it only XYsec is a double, the rest default
to Variant. You must EXPLICITLY dim each variable or it defaults to Variant

Dim ABdeg As Double, ABmin As Double, ABsec As Double, XYdeg As Double,
XYmin As Double, XYsec As Double

If ABdeg = " " Or ABmin = " " Or ABsec = " " Or XYdeg = " " Or XYmin = " "
Or XYsec = " " Then

===>
If ABdeg *ABmin *ABsec*XYdeg *XYmin*XYsec = 0 Then

I assume that you want to test that the value in each cell is non-zero?
multiplying them out this way will return zero if any of the cells are zero

--
Patrick Molloy
Microsoft Excel MVP
---------------------------------
Dani said:
I see I'm not the only one with type mismatch problems!
I'm sure it's really simple but I have a piece of code where the only
undefined element is the name of a function the sub calls at the end. As
far as I know this doesn't need to be dimensioned so what am I doing wrong?
Here is my code:
 
Back
Top