Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / March 2006

Tip: Looking for answers? Try searching our database.

count rows with data

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bryan Brassell - 31 Mar 2006 23:30 GMT
Need to count the number of rows that contain data - ignoring formats.  
Signature

Regards,

Bryan Brassell
Padgett Business Services
281-897-9141

Richard Buttrey - 31 Mar 2006 23:38 GMT
>Need to count the number of rows that contain data - ignoring formats.  

How are you defining data? Is that any piece of information, i.e.
text, formula or number.

Does just one occurence of a piece of data in a row mean that you
count the row, or does every row have to contain data in every cell in
a range of columns before you count the row?

Rgds

__
Richard Buttrey
Grappenhall, Cheshire, UK
__________________________
Bryan Brassell - 31 Mar 2006 23:51 GMT
any data, formulas, numbers, text, etc.  One occurence in the row does count.
Signature

Regards,

Bryan Brassell
Padgett Business Services
281-897-9141

> >Need to count the number of rows that contain data - ignoring formats.  
>
[quoted text clipped - 11 lines]
> Grappenhall, Cheshire, UK
> __________________________
Ken Hudson - 01 Apr 2006 00:45 GMT
Bryan,

Try this code:

Sub RowCount()

Dim Ans As String
Dim R As Long
Dim C As Range
Dim Rng As Range

On Error GoTo EndMacro

If Selection.Rows.Count > 1 Then
   Set Rng = Selection
Else
   Set Rng = ActiveSheet.UsedRange.Rows
End If
For R = Rng.Rows.Count To 1 Step -1
   If Application.WorksheetFunction.CountA(Rng.Rows(R).EntireRow) > 0 Then
       Exit For
   End If
Next R

Ans = MsgBox(R & " rows in worksheet.", vbOKOnly)

EndMacro:

End Sub
Signature

Ken Hudson

> Need to count the number of rows that contain data - ignoring formats.  
Ken Hudson - 01 Apr 2006 00:57 GMT
If I mis-understodd your question and you don't want to count empty rows
interspersed throughout the worksheet, try the code below. (Credit to Chip
Pearson from whom I got the basic logic.)

Sub RowCount()

Dim Ans As String
Dim R As Long
Dim C As Range
Dim Rng As Range
Dim DataRows As Double

On Error GoTo EndMacro

DataRows = 0
If Selection.Rows.Count > 1 Then
   Set Rng = Selection
Else
   Set Rng = ActiveSheet.UsedRange.Rows
End If
For R = Rng.Rows.Count To 1 Step -1
   If Application.WorksheetFunction.CountA(Rng.Rows(R).EntireRow) > 0 Then
       DataRows = DataRows + 1
   End If
Next R

Ans = MsgBox(DataRows & " rows in worksheet.", vbOKOnly)

EndMacro:

End Sub
Signature

Ken Hudson

> Need to count the number of rows that contain data - ignoring formats.  
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.