Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old December 16th, 2005, 04: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.

Reply With Quote
  #2 (permalink)  
Old December 18th, 2007, 03: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

Reply With Quote
Reply


Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 01:54 AM
Copying Rows to New worksheet eusanpe Excel VBA 7 December 21st, 2006 09: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 02:53 PM



All times are GMT -4. The time now is 03:25 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.