Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default fighting the type mismatch error

I want to use cell numerical values from a spreadsheet in a program i
V.B.


Dim value1 As Integer
Dim value2 As Integer
Dim value3 As Integer


value1 = CInt(Worksheets("sheet2").Range("B15"))
value2 = CInt(Worksheets("sheet2").Range("B16"))
value3 = CInt(Worksheets("sheet2").Range("B17"))

If Abs(value1 - value2) <= 0.001 Then
value3 = Rnd() * 0.007

I get a type mismatch error because i am trying to do a math operato
with a worksheets("sheetx").Range("x") value which i think VB think
these are srings and not intergers. Will CInt work for my purpose o
no? Also is my syntax right for calling a cel
(Worrksheets("sheet2").Range("B15"))?
-Mar

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 770
Default fighting the type mismatch error

I am unable to reproduce the error, in XL 2000 it does the computations of
text numbers even without Cint, so can't help there. I do have another
comment, though. Declaring your variables as integers means that they are
rounded/truncated so that .01 becomes 0 and 5.5 becomes 5, for example. I'd
declare them as doubles and use Cdbl if conversion is really required.

hth,

Doug Glancy

"mrmark " wrote in message
...
I want to use cell numerical values from a spreadsheet in a program in
V.B.


Dim value1 As Integer
Dim value2 As Integer
Dim value3 As Integer


value1 = CInt(Worksheets("sheet2").Range("B15"))
value2 = CInt(Worksheets("sheet2").Range("B16"))
value3 = CInt(Worksheets("sheet2").Range("B17"))

If Abs(value1 - value2) <= 0.001 Then
value3 = Rnd() * 0.007

I get a type mismatch error because i am trying to do a math operator
with a worksheets("sheetx").Range("x") value which i think VB thinks
these are srings and not intergers. Will CInt work for my purpose or
no? Also is my syntax right for calling a cell
(Worrksheets("sheet2").Range("B15"))?
-Mark


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default fighting the type mismatch error

This is by no means a fix, but in the future, I've found it easier t
reference worksheets by their sheet number.
In the VB Editor, the upper left window (Project Explorer) lists th
sheet by name, then by number in parenthesis (SheetX). Instead o
Worksheets("sheet2").Range("B15"), you can use Sheet2.Range("B15")..
unless of course, your sheet has a different number.

-Gitcyphe

--
Message posted from http://www.ExcelForum.com

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
Visual Basic Error Run Time Error, Type Mismatch Meg Partridge Excel Discussion (Misc queries) 12 September 10th 08 06:10 PM
Type Mismatch Error David Excel Discussion (Misc queries) 2 December 11th 05 04:46 PM
Help with Error: Type Mismatch rleonard[_2_] Excel Programming 0 June 5th 04 07:46 AM
Type Mismatch Error SRS Man[_2_] Excel Programming 3 April 16th 04 03:49 PM
Type Mismatch Error Need Help Ray Batig Excel Programming 1 September 16th 03 12:57 AM


All times are GMT +1. The time now is 06:00 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"