PC Review


Reply
Thread Tools Rate Thread

Count Rows Bug???

 
 
Dave
Guest
Posts: n/a
 
      16th Oct 2009
Hi,

I am having an issue when I try to counts rows in two separate workbooks. I
am not sure if this is a bug or me. Any assistance would be greatly
appreciated.

In workbook(1)Sheet(1), r is coming up with 1 row when there are actually 64
rows
In workbook(2)sheet(1) s is coming up with 55 rows which is correct.

r = Workbooks(1).Sheets(1).Range("A1").CurrentRegion.Rows.Count
s = Workbooks(2).Sheets(1).Range("A1").CurrentRegion.Rows.Count

I am not sure if I am providing enough information. This code used to work
but has just stopped working yesterday. We are using excel 2003.
--
Thank you

Dave
 
Reply With Quote
 
 
 
 
Patrick Molloy
Guest
Posts: n/a
 
      16th Oct 2009
try explicitly naming the workbook and worksheets ... you can't always be
sure workbooks(1) referes to the correct book.
same with worksheets
in my test "sheet3" was actually sheet(1) so it returned 1 as well.

when opening workbooks you get better control using a workbook object

dim wb as workbook
set wb = workbooks.open({file})

r = wb.Sheets("sheet1").Range("A1").CurrentRegion.Rows.Count
wb.Close false ' closes without saving






"Dave" wrote:

> Hi,
>
> I am having an issue when I try to counts rows in two separate workbooks. I
> am not sure if this is a bug or me. Any assistance would be greatly
> appreciated.
>
> In workbook(1)Sheet(1), r is coming up with 1 row when there are actually 64
> rows
> In workbook(2)sheet(1) s is coming up with 55 rows which is correct.
>
> r = Workbooks(1).Sheets(1).Range("A1").CurrentRegion.Rows.Count
> s = Workbooks(2).Sheets(1).Range("A1").CurrentRegion.Rows.Count
>
> I am not sure if I am providing enough information. This code used to work
> but has just stopped working yesterday. We are using excel 2003.
> --
> Thank you
>
> Dave

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      16th Oct 2009
Since you're relying on the .currentregion, I'm betting that you have a gap (an
empty row) in the middle of your data--so the currentregion isn't what you think
it is.

If you open that offending worksheet and select A1 and hit ctrl-* (or
F5|special|current region), what ends up getting selected?

Dave wrote:
>
> Hi,
>
> I am having an issue when I try to counts rows in two separate workbooks. I
> am not sure if this is a bug or me. Any assistance would be greatly
> appreciated.
>
> In workbook(1)Sheet(1), r is coming up with 1 row when there are actually 64
> rows
> In workbook(2)sheet(1) s is coming up with 55 rows which is correct.
>
> r = Workbooks(1).Sheets(1).Range("A1").CurrentRegion.Rows.Count
> s = Workbooks(2).Sheets(1).Range("A1").CurrentRegion.Rows.Count
>
> I am not sure if I am providing enough information. This code used to work
> but has just stopped working yesterday. We are using excel 2003.
> --
> Thank you
>
> Dave


--

Dave Peterson
 
Reply With Quote
 
Jacob Skaria
Guest
Posts: n/a
 
      16th Oct 2009
Just to add on to what Patrick mentioned..You can try out the below code from
which you can identify where it has gone wrong....or whether the current
region spans to only 1 row...

Msgbox Workbooks(1).Sheets(1).Range("A1").CurrentRegion.address
(External:=true)

If this post helps click Yes
---------------
Jacob Skaria


"Dave" wrote:

> Hi,
>
> I am having an issue when I try to counts rows in two separate workbooks. I
> am not sure if this is a bug or me. Any assistance would be greatly
> appreciated.
>
> In workbook(1)Sheet(1), r is coming up with 1 row when there are actually 64
> rows
> In workbook(2)sheet(1) s is coming up with 55 rows which is correct.
>
> r = Workbooks(1).Sheets(1).Range("A1").CurrentRegion.Rows.Count
> s = Workbooks(2).Sheets(1).Range("A1").CurrentRegion.Rows.Count
>
> I am not sure if I am providing enough information. This code used to work
> but has just stopped working yesterday. We are using excel 2003.
> --
> Thank you
>
> Dave

 
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
datatable rows count and dataview count differ John Hui Microsoft ADO .NET 4 3rd Aug 2010 10:26 PM
VBA to count rows from specific cell and insert rows Valerie Microsoft Excel Programming 3 26th Nov 2007 10:14 PM
Counters?, Count Rows?, Get Rows? in an Excel Macro =?Utf-8?B?Q19UQjI0?= Microsoft Excel Programming 2 3rd Feb 2005 04:29 PM
Re: how do i count rows, and count them by color or a highlight? blue. Frank Kabel Microsoft Excel Worksheet Functions 0 9th Sep 2004 10:05 PM
I am adding a new row to the datagrid dynamically but if i use the Count property of Item it is not showing the count of the new rows being added Praveen Balanagendra via .NET 247 Microsoft ASP .NET 2 6th Jun 2004 08:16 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:34 PM.