Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: Access 2003 VBA Programmer's Reference
This is the forum to discuss the Wrox book Access 2003 VBA Programmer's Reference by Patricia Cardoza, Teresa Hennig, Graham Seach, Armen Stein; ISBN: 9780764559037
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Access 2003 VBA Programmer's Reference section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 16th, 2005, 05:13 PM
Registered User
 
Join Date: Dec 2005
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Counting rows in Excel worksheet

Hey folks, I'm back for some more punishment.

I've an application that must know how many rows in a worksheet are populated with data. Some cells in any given row are expected to not contain data. The first row that contains no data is my endpoint.

What I keep receiving is an Overflow message, presumably because I must be counting every...single...row, until I run out of memory.

Here's my snippet, and from a worksheet that has 2 rows, each containing various columns of data up to 10 columns:

spreadsheet:

    Column 1 Column 2 Column 3
1 green blue pink
2 one two three
3 a b c

Code:
    Dim cnDB As DAO.Database
    Dim rst As DAO.Recordset

    Dim xlsAPP As Excel.Application
    Dim xlsWBK As Excel.Workbook
    Dim xlsWST As Excel.Worksheet
    Dim strPath As String

    If cnt = 1 Then
        msgbox "<placeholder>"
    Else
        Set xlsAPP = New Excel.Application
        strPath = "C:\MyPath\" & "file1.xls"
        xlsAPP.Workbooks.Open (strPath)
        Set xlsWBK = xlsAPP.ActiveWorkbook
        Set xlsWST = xlsWBK.Sheets("WS1")
        xlsWST.Activate

        Dim strstorage As Integer

        With xlsWST
            Do While Not IsNull(.Application.Rows.Cells(, "B"))
                strstorage = .Application.Rows.Count
            Loop
        End With
Thanks for any helpful input.

disclaimer: I will only be using DAO.

 
Old December 18th, 2007, 04:38 AM
Registered User
 
Join Date: Dec 2007
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi. just use the Usedrange function:

worksheet1.UsedRange.Rows.Count





Similar Threads
Thread Thread Starter Forum Replies Last Post
Reflecting changes in Excel Worksheet...???? hunk1985 General .NET 0 September 12th, 2007 06:29 AM
How to continue to next new excel worksheet christine_wmw Classic ASP Basics 0 January 24th, 2007 02:54 AM
Copying Rows to New worksheet eusanpe Excel VBA 7 December 21st, 2006 10:23 AM
Counting Number of Rows Between Data Range eusanpe Excel VBA 6 September 21st, 2006 07:17 AM
Opening excel worksheet in c# GanpatDSouza C# 1 January 23rd, 2004 03:53 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.