Solved

Record count in Excel MARCO VBA

Posted on 2001-06-20
14
543 Views
Last Modified: 2008-02-01
How do I get a record count in Excel???  I just want to know how many records are in a sheet??
Thanks
0
Comment
Question by:strongd
  • 4
  • 4
  • 2
  • +3
14 Comments
 
LVL 2

Expert Comment

by:TrueDrake
Comment Utility
Hi,
Some people use UsedRange but i simply add a function:

Function LastRow()
  For i=1 to 32000
   Cells(i,1).Select
   a = ActiveCell.Value
   if a <> "" then
   LastRow=a-1
   Exit Sub
  Next
End Function

Enjoy
0
 
LVL 2

Expert Comment

by:TrueDrake
Comment Utility
Hi,
Sorry:
Some people use UsedRange but i simply add a function:

Function LastRow()
 For i=1 to 32000
  Cells(i,1).Select
  a = ActiveCell.Value
  if a <> "" then
     LastRow=a-1
     Exit Function
  End If
 Next
End Function

Enjoy
0
 
LVL 2

Expert Comment

by:TrueDrake
Comment Utility
Hi,
Bad day:
Some people use UsedRange but I simply add a function:

Function LastRow()
  For i=1 to 32000
   Cells(i,1).Select
   a = ActiveCell.Value
   If a = "" then
    LastRow=a-1
    Exit Function
   End If
  Next
End Function

Enjoy
0
 
LVL 3

Expert Comment

by:jrspano
Comment Utility
what happens if some one happens to skip a line?
0
 
LVL 2

Expert Comment

by:nfernand
Comment Utility
Hi guys... anothe Idea.

1) Use the CountA function to know how many cells in a range are not empty: =counta(A1:A2000) returns de number of non-empty cells between A1 and A2000.

2) In code... the same thing:

public function RecNumber() as double
RecNumber= Application.WorkSheetFunction.CountA(Range("A1:A2000")
end Function

Bye
0
 
LVL 2

Expert Comment

by:nfernand
Comment Utility
Hi guys... anothe Idea.

1) Use the CountA function to know how many cells in a range are not empty: =counta(A1:A2000) returns de number of non-empty cells between A1 and A2000.

2) In code... the same thing:

public function RecNumber() as double
RecNumber= Application.WorkSheetFunction.CountA(Range("A1:A2000")
end Function

Bye
0
 
LVL 2

Accepted Solution

by:
nfernand earned 50 total points
Comment Utility
Hi guys... anothe Idea.

1) Use the CountA function to know how many cells in a range are not empty: =counta(A1:A2000) returns de number of non-empty cells between A1 and A2000.

2) In code... the same thing:

public function RecNumber() as double
RecNumber= Application.WorkSheetFunction.CountA(Range("A1:A2000")
end Function

Bye
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 2

Expert Comment

by:nfernand
Comment Utility
Opps... sorry.
0
 
LVL 2

Expert Comment

by:chandukb
Comment Utility
ping:
0
 
LVL 3

Expert Comment

by:Hornet241
Comment Utility
Try this

Worksheet.Rows.Count
0
 
LVL 2

Expert Comment

by:TrueDrake
Comment Utility
Hi,


Worksheet.Rows.Count gives 65,536 and is incorrect

public function RecNumber() as double
RecNumber= Application.WorkSheetFunction.CountA(Range("A1:A2000")
end Function

is also OK

Enjoy
0
 
LVL 3

Expert Comment

by:Hornet241
Comment Utility
Sorry

Worksheet.Rows.Count

doesn't really work
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
If you have for sure that blanks rows are not allowed, try this:

Function CountRecs() As Long

Range("A1").Select
Range("A1", Range("A1").End(xlDown)).Select
'MsgBox Selection.Cells.Count
CountRecs = Selection.Cells.Count

End Function
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
With this solution, you need to hard-code the range to count.
Cheers
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now