Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Type change in a declared Variable?
RjS:
It appears that you are picking up some none numeric data and the program is thinking that it is text and treating it as text. The best solution is to convert wsSRC.Cells(i, 13).Value to a single using cSng(wsSRC.Cells(i, 13).Value). Also as an aside it is always better to explicitly declare variables with types so that you pick up the errors when running. In this case vba may covert the number to a single if lCreditSum as dimed as dim lCreditSum as single -- Hope this helps Martin Fishlock Please do not forget to rate this reply. "RjS, CISSP, CISA" wrote: Hi - I have a VB program I wrote for excell some months ago. It has been processing a bank report every day without a hitch for all that time. Today it produced an entirely different and erroneous result. I traced the error to the following statement: lCreditSum = lCreditSum + wsSRC.Cells(i, 13).Value Where lCreditSum is previously declared as a type Single. The SRC value is formatted as a number with 2 decimal points. When I set a watch on the lCreditSum variable and process a previous input report, its type assignment remains as type Single throughout the entire run, but when it processes todays input report the type assignment changes to a "Variant/String" on the very first assignment. It then proceeds to append each new value to the variable instead of adding the new values to the sum as its supposed to. Please, anybody... any suggestions? Absolutely nothing has changed with this program for several months and I have examined in input reports in minute detail and can detect no changes. Thanks much, |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Reference a variable declared in VBA | Excel Worksheet Functions | |||
Type change in a declared Variable? | Excel Programming | |||
Type change in a declared Variable? | Excel Programming | |||
Get an object's type if it's declared as Variant | Excel Programming | |||
Help on combining declared variable and cell formula | Excel Programming |