Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
JoanE
 
Posts: n/a
Default Field length of VBA totals in Excel 2003

Hi,

I've not had much experience using VBA within Excel and have scratched
my head for days on this one.

I have a spreadsheet containing several rows representing bank
statement transactions. They either have a value in a DR or CR column
so I don't have to worry about signs. These values in the spreadsheet
are formatted to 2 decimal places.

I have to produce a batch file for entry to an application that we use.
This file starts with a batch header containing a total of all the
debits and one of all the credits. This is followed by individual
transactions taken from the spreadsheet rows.

I go down the rows totalling the DR and CR columns. This can't be done
on the sheet since several rows are omitted by criteria too complex to
put in a cell formula.

The batch header fields are 13 characters long, padded at the start
with spaces.

My method of working out the number of spaces required was to subtract
the length of my total field from 13, which works most of the time.

However, now and again the total that I would expect to be something
like 2294.94 will appear as 2294.9400000000000001. This obviously gives
my number of space characters a negative value and crashes the macro.

My question is, after all that, how can I get my total to be the
correct length? The above should have been 7, meaning 6 spaces would be
required before it on the batch header. I know how to format a cell to
2 decimal places in VBA but not a variable.

Any assistance gratefully received.

Joan

  #2   Report Post  
Dave O
 
Posts: n/a
Default

Hi, Joan-
Yours is the second post I've seen today that has addressed the idea of
phantom decimal places. As a workaround, you can use the ROUND
function on a variable in your VBA code or in the worksheet that
supplies the data to your code.

An interesting point: your post says These values in the spreadsheet
are formatted to 2 decimal places
.... but this is the displayed value, not the cell's actual value. It
may be worthwhile for you to apply the ROUND function on the worksheet
and to the code, so the numbers all match up.

Dave O

  #3   Report Post  
JoanE
 
Posts: n/a
Default

Hi Dave,

That did the trick. I still don't know where the spurious 1 at the
umpteenth decimal place came from, though. All my input comes from a
bank statement that is already to 2 decimal places which is probably
why I never thought of rounding.

Many thanks.

Joan

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
Microsoft Excel 2003 and Hyperion Retrieve with Excel 2000. Juan Angel Excel Discussion (Misc queries) 1 June 21st 05 09:55 PM
External Links on open and Excel 2003 Guardian Excel Discussion (Misc queries) 3 June 16th 05 12:25 AM
Help in Excel 2003 Charlie Rowe Excel Discussion (Misc queries) 0 June 13th 05 04:31 PM
Excel Range Value issue (Excel 97 Vs Excel 2003) Keeno Excel Discussion (Misc queries) 2 June 13th 05 02:01 PM
sharing/using/saving Excel 2002 files in Excel 2003 maze2009 Excel Discussion (Misc queries) 0 January 20th 05 07:27 PM


All times are GMT +1. The time now is 08:46 PM.

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

About Us

"It's about Microsoft Excel"