Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Record Count (There has to be an easier way...)

Up until now I've been counting the number of records in a particular
sheet with this:

Do
x = x + 1
Loop Until Worksheets(1).Cells(x, 1).Value = ""

This seems like the long way to do this. And it only runs until it
hits a blank cell. Is there an easier way to do this that preferably
won't stop at the first blank line? - Pikus


---
Message posted from http://www.ExcelForum.com/

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default Record Count (There has to be an easier way...)

One way:

Dim nCount As Long
nCount = Range(Cells(n, 1), Cells(Rows.Count, 1).End(xlUp)).Count

where n is your starting row.

In article ,
pikus wrote:

Up until now I've been counting the number of records in a particular
sheet with this:

Do
x = x + 1
Loop Until Worksheets(1).Cells(x, 1).Value = ""

This seems like the long way to do this. And it only runs until it
hits a blank cell. Is there an easier way to do this that preferably
won't stop at the first blank line? - Pikus

  #3   Report Post  
Posted to microsoft.public.excel.programming
raj raj is offline
external usenet poster
 
Posts: 32
Default Record Count (There has to be an easier way...)

Pikus, Try:

dim lngRowCount as long
lngRowCount = activesheet.usedrange.rows.count

HTH

-----Original Message-----
Up until now I've been counting the number of records in

a particular
sheet with this:

Do
x = x + 1
Loop Until Worksheets(1).Cells(x, 1).Value = ""

This seems like the long way to do this. And it only

runs until it
hits a blank cell. Is there an easier way to do this

that preferably
won't stop at the first blank line? - Pikus


---
Message posted from http://www.ExcelForum.com/

.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default Record Count (There has to be an easier way...)

Hi pikus,

You can use the Worksheet function COUNTA from VBA to get the count of
non-blank cells in a range:

MsgBox
Application.WorksheetFunction.CountA(Sheets("Sheet 1").Range("A:A"))

Alternatively, you could use the SpecialCells method:

MsgBox
Sheets("Sheet1").Range("A:A").SpecialCells(xlCellT ypeConstants).Cells.Count

[The latter method assumes the cells you wish to count are constants and not
formulas.]

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

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


pikus wrote:
Up until now I've been counting the number of records in a particular
sheet with this:

Do
x = x + 1
Loop Until Worksheets(1).Cells(x, 1).Value = ""

This seems like the long way to do this. And it only runs until it
hits a blank cell. Is there an easier way to do this that preferably
won't stop at the first blank line? - Pikus


---
Message posted from http://www.ExcelForum.com/


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Record Count (There has to be an easier way...)


msgbox Columns(1).SpecialCells(xlConstants).Count

if the cells have formulas xlFormulas rather than xlConstants

will count the filled cells. If you want to get the last row

msgbox cells(rows.count,1).End(xlup).Row

--
Regards,
Tom Ogilvy


"pikus" wrote in message
...
Up until now I've been counting the number of records in a particular
sheet with this:

Do
x = x + 1
Loop Until Worksheets(1).Cells(x, 1).Value = ""

This seems like the long way to do this. And it only runs until it
hits a blank cell. Is there an easier way to do this that preferably
won't stop at the first blank line? - Pikus


---
Message posted from http://www.ExcelForum.com/





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Record Count (There has to be an easier way...)

THANKS Y'ALL! That rocks! - Piku

--
Message posted from http://www.ExcelForum.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
VBA to total record count Brent E Excel Discussion (Misc queries) 4 November 18th 08 01:47 AM
lloking for an easier way to count Corben Excel Worksheet Functions 2 April 15th 06 10:22 AM
Autofilter record count Debbie Thompson Excel Discussion (Misc queries) 1 February 11th 05 05:32 PM
record count using two different cells Josborne Excel Worksheet Functions 1 November 1st 04 09:51 PM
record of records count for display... BruceJ[_2_] Excel Programming 0 November 11th 03 10:06 PM


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