Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Keep getting "Type mismatch"
'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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Keep getting "Type mismatch"
Try this
Dim deg(1 To 25) As Double, min1 To 25) As Double, sec1 To 25) As Double Dim DEGt(1 To 25) As Double, Zodiac(25) As Double For h = 1 To 25 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 -- HTH Bob "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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Keep getting "Type mismatch"
You have explicitly declared the variable Zodiac as a Double.
The tail end of your code, just above 10: you are trying to set it with a String variable (CStr). Thus, the type mismatch error. "Philosophaie" wrote: '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 |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Keep getting "Type mismatch"
Changed Zodiac(25) to dim as string. Still gives the same error.
"Muscoby" wrote: You have explicitly declared the variable Zodiac as a Double. The tail end of your code, just above 10: you are trying to set it with a String variable (CStr). Thus, the type mismatch error. "Philosophaie" wrote: '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 |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Keep getting "Type mismatch"
Did both of these. Still type mismatch error
Dim Zodiac(23) as String Dim deg(25) As Double, min(25) As Double, sec(25) As Double, etc.... DEGt="" to DEGt=0 tried substituting varient for double - same result |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
Keep getting "Type mismatch"
I told you I didn't think those two items were the source of your problem...
I just wanted you to be aware of them for your future programming efforts. However.... you didn't answer any of the questions I asked. Here they are again... 1. Which line of code is registering the Type Mismatch error (that is, which line is the debugger highlighting)? 2. What data type is the variable "h" declared as? 3. 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 ... Did both of these. Still type mismatch error Dim Zodiac(23) as String Dim deg(25) As Double, min(25) As Double, sec(25) As Double, etc.... DEGt="" to DEGt=0 tried substituting varient for double - same result |
#8
Posted to microsoft.public.excel.programming
|
|||
|
|||
Keep getting "Type mismatch"
1-Type Mismatch on:
deg(h) = CDbl(.Cells(2 + h, 3)) 2- h is an integer 3- With Sheets(1)...End With "Rick Rothstein" wrote: I told you I didn't think those two items were the source of your problem... I just wanted you to be aware of them for your future programming efforts. However.... you didn't answer any of the questions I asked. Here they are again... 1. Which line of code is registering the Type Mismatch error (that is, which line is the debugger highlighting)? 2. What data type is the variable "h" declared as? 3. 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 ... Did both of these. Still type mismatch error Dim Zodiac(23) as String Dim deg(25) As Double, min(25) As Double, sec(25) As Double, etc.... DEGt="" to DEGt=0 tried substituting varient for double - same result . |
#9
Posted to microsoft.public.excel.programming
|
|||
|
|||
Keep getting "Type mismatch"
I can simulate your error only if the statement deg(h) = CDbl(.Cells(2+h,3))
cannot be resolved. In this case because of text characters in the cell. Check the values in the cells. Is it possible there are text strings in these cells such as a degree sign or a temperature scale (C, F, K)? The code isn't wrong, it's just not able to execute because it cannot convert the value in the cell into a double. "Philosophaie" wrote: 1-Type Mismatch on: deg(h) = CDbl(.Cells(2 + h, 3)) 2- h is an integer 3- With Sheets(1)...End With "Rick Rothstein" wrote: I told you I didn't think those two items were the source of your problem... I just wanted you to be aware of them for your future programming efforts. However.... you didn't answer any of the questions I asked. Here they are again... 1. Which line of code is registering the Type Mismatch error (that is, which line is the debugger highlighting)? 2. What data type is the variable "h" declared as? 3. 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 ... Did both of these. Still type mismatch error Dim Zodiac(23) as String Dim deg(25) As Double, min(25) As Double, sec(25) As Double, etc.... DEGt="" to DEGt=0 tried substituting varient for double - same result . |
#10
Posted to microsoft.public.excel.programming
|
|||
|
|||
Keep getting "Type mismatch"
I asked about the values in the cells in the first posting by this OP and he
responded with this... deg(1)=20 min(1)=45 sec(1)=21 DEGt(1)=20.755833333 So the values appear to be numeric. -- Rick (MVP - Excel) "Muscoby" wrote in message ... I can simulate your error only if the statement deg(h) = CDbl(.Cells(2+h,3)) cannot be resolved. In this case because of text characters in the cell. Check the values in the cells. Is it possible there are text strings in these cells such as a degree sign or a temperature scale (C, F, K)? The code isn't wrong, it's just not able to execute because it cannot convert the value in the cell into a double. "Philosophaie" wrote: 1-Type Mismatch on: deg(h) = CDbl(.Cells(2 + h, 3)) 2- h is an integer 3- With Sheets(1)...End With "Rick Rothstein" wrote: I told you I didn't think those two items were the source of your problem... I just wanted you to be aware of them for your future programming efforts. However.... you didn't answer any of the questions I asked. Here they are again... 1. Which line of code is registering the Type Mismatch error (that is, which line is the debugger highlighting)? 2. What data type is the variable "h" declared as? 3. 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 ... Did both of these. Still type mismatch error Dim Zodiac(23) as String Dim deg(25) As Double, min(25) As Double, sec(25) As Double, etc.... DEGt="" to DEGt=0 tried substituting varient for double - same result . |
#11
Posted to microsoft.public.excel.programming
|
|||
|
|||
Keep getting "Type mismatch"
I found the problem. It was in the syntax:
I first entered: deg(h) = CDbl(.Cells(2 + h, 3)) The fix was: deg(h) = CDbl(.Cells(h+2, 3)) Just transposing the variable to the first position and the number to the second fixed the anomaly. Excel did not like the variable in second position like that. |
#12
Posted to microsoft.public.excel.programming
|
|||
|
|||
Keep getting "Type mismatch"
If "h" is declared as an Integer (as you said it was), then that
transposition should not have changed anything... addition is not dependent on order, so I am still puzzled as to why it didn't work originally. -- Rick (MVP - Excel) "Philosophaie" wrote in message ... I found the problem. It was in the syntax: I first entered: deg(h) = CDbl(.Cells(2 + h, 3)) The fix was: deg(h) = CDbl(.Cells(h+2, 3)) Just transposing the variable to the first position and the number to the second fixed the anomaly. Excel did not like the variable in second position like that. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
"Type mismatch" when I try to fill an Array variable with "+" | Excel Discussion (Misc queries) | |||
Error Handling to mitigate "Run Time Erorr 13 Type Mismatch" | Excel Programming | |||
"FIND" generates "Type mismatch" error | Excel Programming | |||
Copying data to another worksheet gives "Type Mismatch" error | Excel Programming |