PC Review


Reply
Thread Tools Rate Thread

Accurately reading the contents of another spreadsheet

 
 
Phil Hibbs
Guest
Posts: n/a
 
      21st Oct 2009
I have a spreadsheet that has VBA that opens, reads, and closes a list
of other spreadsheets and tabs, writing the contents of those
spreadsheets out as CSV files.

The problem that I am encountering is where one of the sheets has a
column that is not wide enough for all the data, so 1234.5678 is read
as 1234.568. I have been getting around this by doing a
Sheet.Columns.AutoFit call when opening each sheet.

This is now breaking on one particular sheet. When I open it, it shows
1234.5678, but when I manually auto-fit the column, it shrinks a
little bit and changes to 1234.568, and this is the same as is
happening in my VBA code.

Any suggestions as to what I can do in my VBA to read the sheet
accurately? I don't want to use the Value2 property, as this breaks
date cells. The only thing I can think of is to do the AutoFit and
then loop through all the columns increasing the widths.

Phil Hibbs.
 
Reply With Quote
 
 
 
 
Robert Flanagan
Guest
Posts: n/a
 
      21st Oct 2009
Try returning the Formula property:

msgbox activecell.formula

returned 1234.5678 when here was an equal sign.

Robert Flanagan
http://www.add-ins.com
Productivity add-ins and downloadable books on VB macros for Excel



"Phil Hibbs" <(E-Mail Removed)> wrote in message
news:d9244294-2fda-4c86-ad35-(E-Mail Removed)...
>I have a spreadsheet that has VBA that opens, reads, and closes a list
> of other spreadsheets and tabs, writing the contents of those
> spreadsheets out as CSV files.
>
> The problem that I am encountering is where one of the sheets has a
> column that is not wide enough for all the data, so 1234.5678 is read
> as 1234.568. I have been getting around this by doing a
> Sheet.Columns.AutoFit call when opening each sheet.
>
> This is now breaking on one particular sheet. When I open it, it shows
> 1234.5678, but when I manually auto-fit the column, it shrinks a
> little bit and changes to 1234.568, and this is the same as is
> happening in my VBA code.
>
> Any suggestions as to what I can do in my VBA to read the sheet
> accurately? I don't want to use the Value2 property, as this breaks
> date cells. The only thing I can think of is to do the AutoFit and
> then loop through all the columns increasing the widths.
>
> Phil Hibbs.



 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      21st Oct 2009
I'm not sure how you are saving your data out (you didn't show us your
code); however, the Value property of a cell should return the full value in
the cell, not the truncated/rounded value shown when the column is too
narrow.

--
Rick (MVP - Excel)


"Phil Hibbs" <(E-Mail Removed)> wrote in message
news:d9244294-2fda-4c86-ad35-(E-Mail Removed)...
>I have a spreadsheet that has VBA that opens, reads, and closes a list
> of other spreadsheets and tabs, writing the contents of those
> spreadsheets out as CSV files.
>
> The problem that I am encountering is where one of the sheets has a
> column that is not wide enough for all the data, so 1234.5678 is read
> as 1234.568. I have been getting around this by doing a
> Sheet.Columns.AutoFit call when opening each sheet.
>
> This is now breaking on one particular sheet. When I open it, it shows
> 1234.5678, but when I manually auto-fit the column, it shrinks a
> little bit and changes to 1234.568, and this is the same as is
> happening in my VBA code.
>
> Any suggestions as to what I can do in my VBA to read the sheet
> accurately? I don't want to use the Value2 property, as this breaks
> date cells. The only thing I can think of is to do the AutoFit and
> then loop through all the columns increasing the widths.
>
> Phil Hibbs.


 
Reply With Quote
 
Phil Hibbs
Guest
Posts: n/a
 
      21st Oct 2009
Robert Flanagan wrote:
> Try returning the Formula property:


Hey, that appears to work! I'll have to do some more testing, but
thanks, I think that might have cracked it. I'll post back here again
if I find any problems with it.

Phil Hibbs.
 
Reply With Quote
 
Phil Hibbs
Guest
Posts: n/a
 
      21st Oct 2009
> Hey, that appears to work! I'll have to do some more testing, but
> thanks, I think that might have cracked it. I'll post back here again
> if I find any problems with it.


It turns out there is a very subtle problem with reading the formula -
some of the cells actually contain formulae, and I want the results of
the formula, not the formula itself.

Phil Hibbs.
 
Reply With Quote
 
Phil Hibbs
Guest
Posts: n/a
 
      21st Oct 2009
Rick Rothstein wrote:
> I'm not sure how you are saving your data out (you didn't show us your
> code); however, the Value property of a cell should return the full value in
> the cell, not the truncated/rounded value shown when the column is too
> narrow.


I could have sworn that we tried the Value property and found a
problem with that, and so used the Text property. There must be a
reason why we used Text. I'll run some tests and see what I can find.

Phil Hibbs.
 
Reply With Quote
 
Phil Hibbs
Guest
Posts: n/a
 
      21st Oct 2009
> I could have sworn that we tried the Value property and found a
> problem with that...


Got it. If the cell has a format, e.g. 2 decimal places, we want that
to be applied. Text gives us that, but Value and Formula don't.

Phil Hibbs.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading contents =?Utf-8?B?RmlvbmE=?= Microsoft Excel Misc 3 28th Jun 2007 02:56 AM
Reading File and adding contents to spreadsheet =?Utf-8?B?S2VybWFuUE0=?= Microsoft Excel Programming 1 13th Jun 2007 12:59 AM
external hd reading contents Dale Randall Computer Hardware 2 10th May 2006 11:04 PM
reading window contents surferboy Windows XP Security 1 19th Feb 2004 09:35 PM
Browsing to URL and reading contents Mike Microsoft Excel Programming 9 20th Nov 2003 07:53 PM


Features
 

Advertising
 

Newsgroups
 


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