Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Reading range w/ 255+ characters throws error

Hi, I need to read an Excel range into an array which I then use to modify
it's data and formulas. I then write the modified data back to Excel. This
code: shtValues = (System.Array)row.Formula;
fails when it encounters 255+ characters in a cell. My code is below. Please
tell me if there's a way to work around this.

try
{
// Creates and initializes a new CollectionBase.
this.oSheetRangeCollection = new RangeCollection();

System.Array shtValues=null;
int iLastCol = ws.UsedRange.Columns.Count;
int iLastRow = ws.UsedRange.Rows.Count;

for (int i = 1; i <= iLastRow; i++)
{
Excel.Range row = (Excel.Range) ws.get_Range(ws.Cells[i, 1], ws.Cells[i,
iLastCol]);
//insert the data into the object[,] one row at a time
shtValues = (System.Array)row.Formula;

this.oSheetRangeCollection.AddRow(shtValues);
nav.ReleaseComObj(row);
}
}

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Reading range w/ 255+ characters throws error

The limit of a formula array is 255 characters, or a even slightly less.

If the formula includes sheet names you might be able to cheat slightly by
temporarily renaming the sheet name to a single character, applying your
formula with the single character names, then renaming the sheet.

Having done that you would not be able to programmatically read the 255+
array formula until you again reduced the sheet names.

Regards,
Peter T

"jarabe28" wrote in message
...
Hi, I need to read an Excel range into an array which I then use to modify
it's data and formulas. I then write the modified data back to Excel. This
code: shtValues = (System.Array)row.Formula;
fails when it encounters 255+ characters in a cell. My code is below.
Please
tell me if there's a way to work around this.

try
{
// Creates and initializes a new CollectionBase.
this.oSheetRangeCollection = new RangeCollection();

System.Array shtValues=null;
int iLastCol = ws.UsedRange.Columns.Count;
int iLastRow = ws.UsedRange.Rows.Count;

for (int i = 1; i <= iLastRow; i++)
{
Excel.Range row = (Excel.Range) ws.get_Range(ws.Cells[i, 1], ws.Cells[i,
iLastCol]);
//insert the data into the object[,] one row at a time
shtValues = (System.Array)row.Formula;

this.oSheetRangeCollection.AddRow(shtValues);
nav.ReleaseComObj(row);
}
}



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Reading range w/ 255+ characters throws error

If I were using VBA...

Take a look at Dick Kusleika's site:
http://www.dailydoseofexcel.com/arch...rmulas-in-vba/

It's a technique to workaround that .formulaarray length limit.

jarabe28 wrote:

Hi, I need to read an Excel range into an array which I then use to modify
it's data and formulas. I then write the modified data back to Excel. This
code: shtValues = (System.Array)row.Formula;
fails when it encounters 255+ characters in a cell. My code is below. Please
tell me if there's a way to work around this.

try
{
// Creates and initializes a new CollectionBase.
this.oSheetRangeCollection = new RangeCollection();

System.Array shtValues=null;
int iLastCol = ws.UsedRange.Columns.Count;
int iLastRow = ws.UsedRange.Rows.Count;

for (int i = 1; i <= iLastRow; i++)
{
Excel.Range row = (Excel.Range) ws.get_Range(ws.Cells[i, 1], ws.Cells[i,
iLastCol]);
//insert the data into the object[,] one row at a time
shtValues = (System.Array)row.Formula;

this.oSheetRangeCollection.AddRow(shtValues);
nav.ReleaseComObj(row);
}
}


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Reading range w/ 255+ characters throws error

"Dave Peterson" wrote in message
If I were using VBA...

Take a look at Dick Kusleika's site:
http://www.dailydoseofexcel.com/arch...rmulas-in-vba/

It's a technique to workaround that .formulaarray length limit.


I forgot about that, yes a cunning trick (also a clever calendar formula in
the demo)

"Dave sent me a solution to this problem that's shown below."
Don't suppose you know which "Dave" ...?

Regards,
Peter T



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Reading range w/ 255+ characters throws error

I don't think it was me.


Peter T wrote:

"Dave Peterson" wrote in message
If I were using VBA...

Take a look at Dick Kusleika's site:
http://www.dailydoseofexcel.com/arch...rmulas-in-vba/

It's a technique to workaround that .formulaarray length limit.


I forgot about that, yes a cunning trick (also a clever calendar formula in
the demo)

"Dave sent me a solution to this problem that's shown below."
Don't suppose you know which "Dave" ...?

Regards,
Peter T


--

Dave Peterson
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
Code window changes case and throws error owlnevada Excel Programming 1 March 31st 09 08:03 PM
Find Throws Error 91 Dave Birley Excel Programming 13 May 17th 07 07:01 PM
How do I perform a certain function if VBA throws up an error? Matt[_37_] Excel Programming 2 February 24th 06 03:06 PM
Range.Formula in Excel 2003 gives Error reading formulas just below 1024 bytes Frank Jones Excel Programming 14 July 9th 04 06:25 AM
Format statement no longer throws an error PF[_2_] Excel Programming 6 March 4th 04 02:44 PM


All times are GMT +1. The time now is 07:11 AM.

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"