PC Review


Reply
Thread Tools Rate Thread

CDbl and "Type mismatch"

 
 
Philosophaie
Guest
Posts: n/a
 
      25th Mar 2010
Neither of these cases work. I just get a "Type mismatch" error.

Dim deg(10), min(10), sec(10), DEGt(10) as Double

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
or
deg(h) = .Cells(2 + h, 3)
min(h) = .Cells(2 + h, 4)
sec(h) = .Cells(2 + h, 5))
DEGt(h) = CDbl(deg(h)) + CDbl(min(h)) / 60 + CDbl(sec(h)) / 3600
 
Reply With Quote
 
 
 
 
Rick Rothstein
Guest
Posts: n/a
 
      26th Mar 2010
I'm guessing "h" is a loop variable... what values does it iterate over?
Also, **exactly** what is in your cells that you are trying to convert (show
us an example or two)? Also, I see a "dot" in front of the Cells call...
what is it having the cell refer back to?

--
Rick (MVP - Excel)



"Philosophaie" <(E-Mail Removed)> wrote in message
news:23889DEA-C7AC-4FFC-A9C3-(E-Mail Removed)...
> Neither of these cases work. I just get a "Type mismatch" error.
>
> Dim deg(10), min(10), sec(10), DEGt(10) as Double
>
> 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
> or
> deg(h) = .Cells(2 + h, 3)
> min(h) = .Cells(2 + h, 4)
> sec(h) = .Cells(2 + h, 5))
> DEGt(h) = CDbl(deg(h)) + CDbl(min(h)) / 60 + CDbl(sec(h)) / 3600


 
Reply With Quote
 
Philosophaie
Guest
Posts: n/a
 
      26th Mar 2010
for h = 1 to 23
...
next h

deg(1)=20
min(1)=45
sec(1)=21
DEGt(1)=20.755833333
 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      26th Mar 2010
I'm not entirely sure why you are getting a "Type Mismatch" error, at least
not with the code fragment you showed us (maybe the error is occurring
elsewhere in your code), but your array limits are wrong. You showed this in
your code...

> Dim deg(10), min(10), sec(10), DEGt(10) as Double


and you just told me this...

> for h = 1 to 23


so when "h" hits 11, there will be a problem as your array is not big enough
to hold that index value (but I would not expect a "Type Mismatch" error to
be occurring for it). Perhaps if you post all of your code (copy/paste it,
don't retype it as I see some mistyping in the code you posted originally).

--
Rick (MVP - Excel)



"Philosophaie" <(E-Mail Removed)> wrote in message
news:302FD2FA-1010-4ED4-9EA8-(E-Mail Removed)...
> for h = 1 to 23
> ...
> next h
>
> deg(1)=20
> min(1)=45
> sec(1)=21
> DEGt(1)=20.755833333


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cdbl and Cstr with a "Type Mismatch" Error Philosophaie Microsoft Excel Programming 6 3rd Apr 2010 06:14 AM
Avoid Type Mismatch Error when using CDBL() ExcelMonkey Microsoft Excel Programming 3 13th May 2009 07:51 PM
"Type mismatch" when I try to fill an Array variable with "+" EagleOne@discussions.microsoft.com Microsoft Excel Misc 1 17th Apr 2007 01:28 PM
I have a data type mismatch if I select "H", but "A" selects. =?Utf-8?B?SG93YXJkIGluIEhhbW1vbmRzcG9ydA==?= Microsoft Access 4 6th Nov 2005 05:05 PM
"FIND" generates "Type mismatch" error =?Utf-8?B?cXVhcnR6?= Microsoft Excel Programming 5 16th Nov 2004 03:29 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:14 PM.