PC Review


Reply
Thread Tools Rate Thread

how to calculate with vba the number of records in an excel- table?

 
 
André
Guest
Posts: n/a
 
      10th Nov 2006
Hi,

I need the number of records in a table, and i need it into a variable in
VBA.

Thanks again
Britt


 
Reply With Quote
 
 
 
 
vezerid
Guest
Posts: n/a
 
      10th Nov 2006
One way (using worksheet function):

Dim NumRec as Long
....
NumRec =
Application.WorksheetFunction.COUNTA(Sheets("Data").Range("A:A"))

HTH
Kostis Vezerides

André wrote:
> Hi,
>
> I need the number of records in a table, and i need it into a variable in
> VBA.
>
> Thanks again
> Britt


 
Reply With Quote
 
Britt
Guest
Posts: n/a
 
      10th Nov 2006
Hi, thanks for replying.

My problem is that i never know the range.
Suppose table "mydata" with the fieldrow in A5:F5 and the real records from
A6:F6. But the number of records will be different each time (those records
are coming from an external source).

So i need something like counting the rows of "mytable", but without using a
given range because it varies each time.

Thanks





"vezerid" <(E-Mail Removed)> schreef in bericht
news:(E-Mail Removed)...
One way (using worksheet function):

Dim NumRec as Long
....
NumRec =
Application.WorksheetFunction.COUNTA(Sheets("Data").Range("A:A"))

HTH
Kostis Vezerides

André wrote:
> Hi,
>
> I need the number of records in a table, and i need it into a variable in
> VBA.
>
> Thanks again
> Britt



 
Reply With Quote
 
vezerid
Guest
Posts: n/a
 
      10th Nov 2006
The solution that I gave you caters exactly to this specification. If
sheet name and columns are fixed then COUNTA(A:A) will examine the
entire column and see how many records you have.

Don't forget to subtract, if necessary, the number of items in column
A:A that are not part of the table. This includes the field heading in
A5 as well as possible other items in A1:A4.

HTH
Kostis Vezerides


Britt wrote:
> Hi, thanks for replying.
>
> My problem is that i never know the range.
> Suppose table "mydata" with the fieldrow in A5:F5 and the real records from
> A6:F6. But the number of records will be different each time (those records
> are coming from an external source).
>
> So i need something like counting the rows of "mytable", but without using a
> given range because it varies each time.
>
> Thanks
>
>
>
>
>
> "vezerid" <(E-Mail Removed)> schreef in bericht
> news:(E-Mail Removed)...
> One way (using worksheet function):
>
> Dim NumRec as Long
> ...
> NumRec =
> Application.WorksheetFunction.COUNTA(Sheets("Data").Range("A:A"))
>
> HTH
> Kostis Vezerides
>
> André wrote:
> > Hi,
> >
> > I need the number of records in a table, and i need it into a variable in
> > VBA.
> >
> > Thanks again
> > Britt


 
Reply With Quote
 
Britt
Guest
Posts: n/a
 
      11th Nov 2006
Indeed, thanks

"vezerid" <(E-Mail Removed)> schreef in bericht
news:(E-Mail Removed)...
The solution that I gave you caters exactly to this specification. If
sheet name and columns are fixed then COUNTA(A:A) will examine the
entire column and see how many records you have.

Don't forget to subtract, if necessary, the number of items in column
A:A that are not part of the table. This includes the field heading in
A5 as well as possible other items in A1:A4.

HTH
Kostis Vezerides


Britt wrote:
> Hi, thanks for replying.
>
> My problem is that i never know the range.
> Suppose table "mydata" with the fieldrow in A5:F5 and the real records
> from
> A6:F6. But the number of records will be different each time (those
> records
> are coming from an external source).
>
> So i need something like counting the rows of "mytable", but without using
> a
> given range because it varies each time.
>
> Thanks
>
>
>
>
>
> "vezerid" <(E-Mail Removed)> schreef in bericht
> news:(E-Mail Removed)...
> One way (using worksheet function):
>
> Dim NumRec as Long
> ...
> NumRec =
> Application.WorksheetFunction.COUNTA(Sheets("Data").Range("A:A"))
>
> HTH
> Kostis Vezerides
>
> André wrote:
> > Hi,
> >
> > I need the number of records in a table, and i need it into a variable
> > in
> > VBA.
> >
> > Thanks again
> > Britt



 
Reply With Quote
 
Dana DeLouis
Guest
Posts: n/a
 
      11th Nov 2006
Hi. I may be wrong, but in your external data link, I believe the range
name will grow/shrink as the size of your data changes. Check the option
"If the number of rows in the data range changes upon refresh: "

Maybe something like this...

Dim NumRec As Long
'// Don't count the Heading Row
NumRec = Range("MyData").Rows.Count - 1

--
HTH :>)
Dana DeLouis
Windows XP & Office 2003


"Britt" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Indeed, thanks
>
> "vezerid" <(E-Mail Removed)> schreef in bericht
> news:(E-Mail Removed)...
> The solution that I gave you caters exactly to this specification. If
> sheet name and columns are fixed then COUNTA(A:A) will examine the
> entire column and see how many records you have.
>
> Don't forget to subtract, if necessary, the number of items in column
> A:A that are not part of the table. This includes the field heading in
> A5 as well as possible other items in A1:A4.
>
> HTH
> Kostis Vezerides
>
>
> Britt wrote:
>> Hi, thanks for replying.
>>
>> My problem is that i never know the range.
>> Suppose table "mydata" with the fieldrow in A5:F5 and the real records
>> from
>> A6:F6. But the number of records will be different each time (those
>> records
>> are coming from an external source).
>>
>> So i need something like counting the rows of "mytable", but without
>> using a
>> given range because it varies each time.
>>
>> Thanks
>>
>>
>>
>>
>>
>> "vezerid" <(E-Mail Removed)> schreef in bericht
>> news:(E-Mail Removed)...
>> One way (using worksheet function):
>>
>> Dim NumRec as Long
>> ...
>> NumRec =
>> Application.WorksheetFunction.COUNTA(Sheets("Data").Range("A:A"))
>>
>> HTH
>> Kostis Vezerides
>>
>> André wrote:
>> > Hi,
>> >
>> > I need the number of records in a table, and i need it into a variable
>> > in
>> > VBA.
>> >
>> > Thanks again
>> > Britt

>
>



 
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
Re: Calculate number of records in a Group Greg Glynn Microsoft Excel Programming 0 19th Dec 2006 02:43 AM
how to calculate with vba the number of records in an excel- table? André Microsoft Excel Misc 5 11th Nov 2006 01:30 PM
How to calculate the number of records in my query awu Microsoft Access Queries 1 9th Oct 2005 07:11 AM
Number of Records pulled by Query don't match number of records in table Rebekah Microsoft Access Queries 7 15th Sep 2004 08:08 PM
Calculate number of records Linda Microsoft Access Reports 2 23rd Dec 2003 10:20 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:42 PM.