View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein Rick Rothstein is offline
external usenet poster
 
Posts: 5,934
Default Keep getting "Type mismatch"

Two things about your coding, neither of which should be contributing to
your problem. First, this line from your code is not doing what you think it
is doing...

Dim deg(25), min(25), sec(25), DEGt(25), Zodiac(25) As Double

Only Zodiac is being Dim'med as a Double, all the rest get Dim'med as
Variant. Unlike other languages, VB requires you to explicitly declare each
variable data type individually. So, you line of code should be this...

Dim deg(25) As Double, min(25) As Double, sec(25) As Double, etc....

Second, you If..Then block of code can be constructed without using the GoTo
statement (making it cleaner and clearer in my opinion) like this...

For h = 1 To 23
If .Cells(2 + h, 3) = "" Then
DEGt(h) = ""
Else
deg(h) = CDbl(.Cells(2 + h, 3))
min(h) = CDbl(.Cells(2 + h, 4))
sec(h) = CDbl(.Cells(2 + h, 5))
DEGt(h) = deg(h) + min(h) / 60 + sec(h) / 3600
Zodiac(h) = CStr(.Cells(2 + h, 2))
End If
Next h

Now, as I said, I really don't think either of these is contribution to your
error problem. Which line of code is registering the Type Mismatch error
(that is, which line is the debugger highlighting)? Also, what data type is
the variable "h" declared as? I also see you have "dots" in front of your
Cells calls... I assume these lines of code are within an active
With...EndWith block, correct (although, again, this shouldn't be producing
a Type Mismatch error)?

--
Rick (MVP - Excel)



"Philosophaie" wrote in message
...
'I do not understand this error. I first tried without the if statement
and
10: that was not the problem. I tried changing the dim statement from 25
to
23 that did not work. I think I am initilizing it right. Just not sure.

Dim deg(25), min(25), sec(25), DEGt(25), Zodiac(25) As Double
For h = 1 To 23
If .Cells(2 + h, 3) = "" Then
DEGt(h) = ""
GoTo 10
End If
deg(h) = CDbl(.Cells(2 + h, 3))
min(h) = CDbl(.Cells(2 + h, 4))
sec(h) = CDbl(.Cells(2 + h, 5))
DEGt(h) = deg(h) + min(h) / 60 + sec(h) / 3600
Zodiac(h) = CStr(.Cells(2 + h, 2))
10:
Next h