Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Visual Basic Error Run Time Error, Type Mismatch | Excel Discussion (Misc queries) | |||
Type Mismatch Error | Excel Discussion (Misc queries) | |||
Help with Error: Type Mismatch | Excel Programming | |||
Type Mismatch Error | Excel Programming | |||
Type Mismatch Error Need Help | Excel Programming |