+ Reply to Thread
Results 1 to 7 of 7

Counting all the records in activesheet

  1. #1
    Registered User
    Join Date
    02-01-2010
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    10

    Counting all the records in activesheet

    Hello,

    I am trying to count all the records in the active worksheet and exporting it to the database(sql.).

    Please Login or Register  to view this content.
    In 'lastRow' i should be getting total number of records in the worksheet,but i m getting only half.
    Could anyone suggest what i should be using instead?

  2. #2
    Valued Forum Contributor JeanRage's Avatar
    Join Date
    03-02-2009
    Location
    Nice, France
    MS-Off Ver
    Excel 2003
    Posts
    705

    Re: Counting all the records in activesheet

    Hi,
    LastRow = Cells(Cells.Rows.Count,"A").End(xlUp).Row
    HTH

  3. #3
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Counting all the records in activesheet

    You can use something like this which will return the last row in column A:

    Please Login or Register  to view this content.
    Assuming your data starts in row 1 with headings and there is an entry in every row that -1 would give you the number of records.

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  4. #4
    Registered User
    Join Date
    02-01-2010
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Counting all the records in activesheet

    Thanks for ur replly, but i am getting the error:

    Run-Tme error @1004': Application defined or object defined error.

  5. #5
    Registered User
    Join Date
    02-01-2010
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Counting all the records in activesheet

    I did this:

    Dim shtSheetToWork As Worksheet
    Set shtSheetToWork = ActiveWorkbook.Worksheets("Data")

    LastRow = shtSheetToWork.UsedRange.Rows.Count
    It gives more then the used range.

  6. #6
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Counting all the records in activesheet

    Which one give you the error?

    This should work fine:

    Please Login or Register  to view this content.

    Dom

  7. #7
    Registered User
    Join Date
    02-01-2010
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: Counting all the records in activesheet

    Thanks for your help.It worked fine. I was selecting used cells, and i think it was selecting empty rows as well coz i must have selected it by mistake.
    Thanks you very much for your help.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1