Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Finding the number of rows on a worksheet

Hello,

I am writing a VBA procedure in MS-Access 2002 to read rows from an Excel
worksheet and copy them to an Access table. Is there a way to know the total
number of populated rows without reading through all of them and looking for
an end of range marker such as an empty cell? That's what I'm doing
currently. Unfortunately some populated rows have empty cells.



Thanks in advance

--
Jonathan
KingsKinght1 <at hotmail <dot com


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Finding the number of rows on a worksheet

Depending on the format of your worksheet, and on exactly what you mean
by
"populated", you might be able to use something like
Application.CountA ("A:A") or ActiveWorksheet.UsedRange.Rows.Count

Andrew Taylor


Jonathan wrote:
Hello,

I am writing a VBA procedure in MS-Access 2002 to read rows from an Excel
worksheet and copy them to an Access table. Is there a way to know the total
number of populated rows without reading through all of them and looking for
an end of range marker such as an empty cell? That's what I'm doing
currently. Unfortunately some populated rows have empty cells.



Thanks in advance

--
Jonathan
KingsKinght1 <at hotmail <dot com


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default Finding the number of rows on a worksheet

You can give this a try...

msgbox sheet1.cells(rows.count, "A").end(xlUp).row

This is better than used range which can be problematic...
--
HTH...

Jim Thomlinson


"Jonathan" wrote:

Hello,

I am writing a VBA procedure in MS-Access 2002 to read rows from an Excel
worksheet and copy them to an Access table. Is there a way to know the total
number of populated rows without reading through all of them and looking for
an end of range marker such as an empty cell? That's what I'm doing
currently. Unfortunately some populated rows have empty cells.



Thanks in advance

--
Jonathan
KingsKinght1 <at hotmail <dot com



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Finding the number of rows on a worksheet

Range("A1").CurrentRegion.Rows.count

to test if this is suitable, click in A1 or any cell in the data and do
Ctlr+shift+8 and see if all your data is selected.

--
Regards,
Tom Ogilvy

"Jonathan" wrote in message
...
Hello,

I am writing a VBA procedure in MS-Access 2002 to read rows from an Excel
worksheet and copy them to an Access table. Is there a way to know the

total
number of populated rows without reading through all of them and looking

for
an end of range marker such as an empty cell? That's what I'm doing
currently. Unfortunately some populated rows have empty cells.



Thanks in advance

--
Jonathan
KingsKinght1 <at hotmail <dot com




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default Finding the number of rows on a worksheet

Jonathan,

Here's a generic function that will return the last used row (given a column
number) for a particular worksheet:

Public Function glGetLastRow(Optional rwsTarget As Worksheet _
= Nothing, Optional rnColNum As Integer = 1) As Long
If rwsTarget Is Nothing Then Set rwsTarget = ActiveSheet
With rwsTarget
glGetLastRow = .Cells(.Rows.Count, rnColNum).End(xlUp).Row
End With
End Function

If you don't pass in a worksheet reference, it will work off of the active
sheet; if you don't pass in a column number, it will use column A when
calculating the last used row. There are alternatives (such as Tom's
solution) that will work better for situations that may have scattered data
where you want the last row with data *anywhere* in it.

--
Regards,

Jake Marx
www.longhead.com


[please keep replies in the newsgroup - email address unmonitored]

Jonathan wrote:
Hello,

I am writing a VBA procedure in MS-Access 2002 to read rows from an
Excel worksheet and copy them to an Access table. Is there a way to
know the total number of populated rows without reading through all
of them and looking for an end of range marker such as an empty cell?
That's what I'm doing currently. Unfortunately some populated rows
have empty cells.



Thanks in advance





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Finding the number of rows on a worksheet

Thank you all for your responses. Tom's solution works for my application
but I am filing them all away for future reference. Thanks again for your
input

-Jonathan

"Jonathan" wrote in message
...
Hello,

I am writing a VBA procedure in MS-Access 2002 to read rows from an Excel
worksheet and copy them to an Access table. Is there a way to know the

total
number of populated rows without reading through all of them and looking

for
an end of range marker such as an empty cell? That's what I'm doing
currently. Unfortunately some populated rows have empty cells.



Thanks in advance

--
Jonathan
KingsKinght1 <at hotmail <dot com




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
finding a number within a text and numbers for multiple rows Darshan Excel Worksheet Functions 4 December 16th 08 02:59 PM
Finding the number of a worksheet GeorgeJ Excel Discussion (Misc queries) 2 July 27th 07 09:02 PM
finding the number of rows and the first row with a specific value rjamison Excel Programming 0 June 14th 05 12:14 AM
finding the number of rows and the first row with a specific value rjamison Excel Programming 0 June 14th 05 12:14 AM
finding the number of rows and the first row with a specific value Bruce Bowler Excel Programming 4 April 20th 05 04:23 PM


All times are GMT +1. The time now is 02:27 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"