Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default used range question

Hi,

I'm using Office Automation to work on an excelsheet...
I need to count the filled rows, I do this by following code:

Range range;
Range usedRange;
range = actualSheet.GetUsedRange();
usedRange = range.GetRows();
int nRows = usedRange.GetCount();

When I create a new Excel Sheet this works fine, but with some files i get
wrong values in nRows.
The file www.beresko.de/test.xls has 1220 filled rows but my code returns a
value of 2295.

Is this my fault or a bug, can anyone help me?

best regards
Andreas



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default used range question

Andreas,

When the used range gets set, it stays at that point even if rows get
deleted. You need to force a reset, so see
http://www.contextures.com/xlfaqApp.html#Unused for some help.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Andreas Beresko" wrote in message
...
Hi,

I'm using Office Automation to work on an excelsheet...
I need to count the filled rows, I do this by following code:

Range range;
Range usedRange;
range = actualSheet.GetUsedRange();
usedRange = range.GetRows();
int nRows = usedRange.GetCount();

When I create a new Excel Sheet this works fine, but with some files i get
wrong values in nRows.
The file www.beresko.de/test.xls has 1220 filled rows but my code returns

a
value of 2295.

Is this my fault or a bug, can anyone help me?

best regards
Andreas





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default used range question

It isn't a bug - it is an incorrect interpretation of what UsedRange
defines. UsedRange defines the area Excel maintains detailed information
on. An excel worksheet can have 65536 rows x 256 columns, but any area that
is not used, is virtual. Excel does not maintain any information on that
area. Other changed besides containing visible values can cause excel to
maintain information on an area.

If your worksheets is set up like a database with information beginning in
A1, try using

Range("A1").CurrentRegion

--
Regards,
Tom Ogilvy

"Andreas Beresko" wrote in message
...
Hi,

I'm using Office Automation to work on an excelsheet...
I need to count the filled rows, I do this by following code:

Range range;
Range usedRange;
range = actualSheet.GetUsedRange();
usedRange = range.GetRows();
int nRows = usedRange.GetCount();

When I create a new Excel Sheet this works fine, but with some files i get
wrong values in nRows.
The file www.beresko.de/test.xls has 1220 filled rows but my code returns

a
value of 2295.

Is this my fault or a bug, can anyone help me?

best regards
Andreas





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default used range question


If your worksheets is set up like a database with information beginning in
A1, try using

Range("A1").CurrentRegion


Thanks a lot, this works fine :-)

best regards


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
range question JT[_2_] Excel Programming 2 November 18th 04 06:13 PM
Range question strataguru[_20_] Excel Programming 1 October 7th 04 12:21 AM
Used Range Question a Excel Programming 2 May 26th 04 03:45 AM
Range question Lee dengo Excel Programming 2 May 25th 04 09:41 PM
Range.Formula and Range question using Excel Automation [email protected] Excel Programming 0 September 19th 03 04:53 AM


All times are GMT +1. The time now is 11:00 PM.

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"