Results 1 to 4 of 4

Thread: Get number of rows with data in a Range in Excel

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Location
    Ont, Canada, Earth
    Posts
    458

    Get number of rows with data in a Range in Excel

    My excel sheet looks like this
    row 1 to row 150 have data and formating
    row 151 to row 1600 have formating only

    I need to find out the last row with DATA ONLY in Excel, however when I use the code below the count shows 1600 - all rows that have cell formating (backcolor etc) applied even if those cells have no data in them.

    VB Code:
    1. UsedRange.Rows.Count

    I also tried these with same problem:
    VB Code:
    1. ws.Cells.SpecialCells(xlCellTypeLastCell).row
    2.   xlApp.ActiveCell.SpecialCells(xlLastCell).Address(RowAbsolute:=False)
    3.   ws.UsedRange.Rows.Count
    4.   ActiveCell.SpecialCells(xlLastCell).row


    How can I get the count of all the rows with data only.
    Thanks

    Tomexx.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Get number of rows with data in a Range in Excel

    You could try using the const. xlCellTypeBlanks. Cells with formatting may or may not be considered blank.
    I cant remember, but the const. xlCellTypeSameFormatConditions will get you the cells with the same formats,
    this may also help.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Location
    Ont, Canada, Earth
    Posts
    458

    Re: Get number of rows with data in a Range in Excel

    Thanks RobDog888 I'll try that.

    Could you help me with this one as well? I'm stuck.

    http://www.vbforums.com/showthread.p...ht=Excel+array
    Thanks

    Tomexx.

  4. #4
    Addicted Member
    Join Date
    Jan 2005
    Posts
    138

    Re: Get number of rows with data in a Range in Excel

    You can also do this:

    VB Code:
    1. Dim topCel As Range, bottomCel As Range
    2. Dim NoOfRows As Integer, a As Integer
    3.  
    4. 'Count entries
    5. With ActiveSheet
    6.     Set topCel = .Range("A1").
    7.     Set bottomCel = .Cells((65536), topCel.Column).End(xlUp)
    8.         If bottomCel.Row <= topCel.Row Then
    9.         Exit Sub
    10.         End If
    11. NoOfRows = .Range(topCel, bottomCel).Rows.Count
    12. End With
    Last edited by D-niss; Apr 25th, 2005 at 05:13 PM.

Posting Permissions

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



Click Here to Expand Forum to Full Width