Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 110
Default Cdbl and Cstr with a "Type Mismatch" Error

Sub This()
Dim A,B,C as Double
Dim S as String
With Sheets("Sheet1")
A=.cells(1,1)
B=.cells(1,2)
C=.cells(1,3)
S=.cells(1,4)
End With
End Sub

This worked one time after that a "Type mismatch" error. Tried these
solutions but none worked:

A=Cdbl(.cells(1,1))
B=Cdbl.cells(1,2))
C=Cdbl(.cells(1,3))
S=Cstr(.cells(1,4))

A=.cells(1,1).Value
B=.cells(1,2).Value
C=.cells(1,3).Value
S=.cells(1,4)

Where am I going wrong?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 464
Default Cdbl and Cstr with a "Type Mismatch" Error

The error suggests that you don't have numbers in your cells and one or more
contains text.


--
Regards
Dave Hawley
www.ozgrid.com

"Philosophaie" wrote in message
...
Sub This()
Dim A,B,C as Double
Dim S as String
With Sheets("Sheet1")
A=.cells(1,1)
B=.cells(1,2)
C=.cells(1,3)
S=.cells(1,4)
End With
End Sub

This worked one time after that a "Type mismatch" error. Tried these
solutions but none worked:

A=Cdbl(.cells(1,1))
B=Cdbl.cells(1,2))
C=Cdbl(.cells(1,3))
S=Cstr(.cells(1,4))

A=.cells(1,1).Value
B=.cells(1,2).Value
C=.cells(1,3).Value
S=.cells(1,4)

Where am I going wrong?


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 110
Default Cdbl and Cstr with a "Type Mismatch" Error

All the cells I have referenced have a number in them.
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 464
Default Cdbl and Cstr with a "Type Mismatch" Error

I can't reproduce the error from your code. But I have to ask, why are you
passing a number to a String variable?


--
Regards
Dave Hawley
www.ozgrid.com


"Philosophaie" wrote in message
...
All the cells I have referenced have a number in them.


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 110
Default Cdbl and Cstr with a "Type Mismatch" Error

Here is an Excerpt from my code:

Private Sub CommandButton1_Click()
Dim d,deg(12), min(12), sec(12), DEGt(24, 2) As Double
Dim Zodiac(12) As String
Dim h, k, cc, jm As Integer
Dim constell As String
With Sheets("Sheet1")
For d = 1 To 2
For h = 1 To 12
deg(h) = (.Cells(h + 4, 3 + 4 * d))
min(h) = (.Cells(h + 4, 4 + 4 * d))
sec(h) = (.Cells(h + 4, 5 + 4 * d))
DEGt(h, dates) = (deg(h)) + (min(h)) / 60
Zodiac(h) = .Cells(h + 4, 2 + 4 * (dates - 1))
Next h
Next d
End Sub



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Cdbl and Cstr with a "Type Mismatch" Error

I have not tested any of your code but I wonder if you have Option Base 1 set
so that the array elements number from 1 and not from zero.

Actually when dimensioning arrays it is a good idea to set the array base
when dimensioning instead of using Option Base 1 like the following.

Dim deg(1 to 12), min(1 to 12)

then for the 2 dimension arrays

DEGt(1 to 24, 1 to 2) As Double

The above method ensures that the first element number is 1. It also makes
the code transportable to any module without having to remember the Option
Base 1 and it is also possible to have both types of dimensioning in the code.


--
Regards,

OssieMac


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Cdbl and Cstr with a "Type Mismatch" Error

Having a closer look at your code I cannot come to grips with what you are
attempting to do. You have 2 nested loops which is fine if all are 2
dimension arrays but the arrays with one dimension in For h = 1 To 12 get
assigned first one value then it is over written with the second loop of For
d = 1 To 2.

You should only have one loop from 1 to 12 and the array with 2 dimensions
should be populated with 2 lines of code like the following. (I have used the
element numbers for the second dimension because I don't know what value to
use for Dates - It should be 1 or 2).

For h = 1 To 12
deg(h) = (.Cells(h + 4, 3 + 4 * d))
min(h) = (.Cells(h + 4, 4 + 4 * d))
sec(h) = (.Cells(h + 4, 5 + 4 * d))
DEGt(h, 1) = (deg(h)) + (min(h)) / 60
DEGt(h, 2) = 'Whatever it should equal
Zodiac(h) = .Cells(h + 4, 2 + 4 * (dates - 1))
Next h



--
Regards,

OssieMac


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
CDbl and "Type mismatch" Philosophaie Excel Programming 3 March 26th 10 02:00 AM
Avoid Type Mismatch Error when using CDBL() ExcelMonkey Excel Programming 3 May 13th 09 07:51 PM
Error Handling to mitigate "Run Time Erorr 13 Type Mismatch" ExcelMonkey Excel Programming 3 October 16th 05 01:56 PM
"FIND" generates "Type mismatch" error quartz[_2_] Excel Programming 5 November 16th 04 03:29 PM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"