Results 1 to 7 of 7

Thread: [RESOLVED] Number of lines of a excel sheet

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2006
    Posts
    13

    Resolved [RESOLVED] Number of lines of a excel sheet

    Hello,

    I have a excel sheet and i want to know the last line that is filled with data. I want to do this and next i want to loop every cells of column until the last line filled with data. Can anyone help me?

    Thanks.

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

    Re: Number of lines of a excel sheet

    You can use either the .UsedRange or .SpecialCells to do this.
    SpecialCells will give you the next available row/column where UsedRange will give the last "used" row/column.

    VB Code:
    1. Sheet1.UsedRange.End(xlDown).row
    2. Sheet1.UsedRange.End(xlToRight).Column
    3. 'Or
    4. Sheet1.Cells.SpecialCells(xlCellTypeLastCell).Row
    5. Sheet1.Cells.SpecialCells(xlCellTypeLastCell).Column
    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
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Number of lines of a excel sheet

    Code:
    msgbox "Last Row : " & sht.cells(65535,1).end(xlup).row
    an alternative
    - assumes column1 (a) has continous data
    - sht is the worksheet - activesheet

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  4. #4

    Thread Starter
    New Member
    Join Date
    Jun 2006
    Posts
    13

    Re: Number of lines of a excel sheet

    Sub pinta()

    Worksheets("Sheet1").Activate
    For Each c In Worksheets("Sheeet1").Range("A1", Range("A1").End(xlDown)).Cells
    Select Case c.Value
    Case 9
    'Worksheets("Sheet1").Range(c, Range(c).End(xlToRight)).Interior.Color = RGB(215, 235, 255)
    c.Interior.Color = RGB(215, 235, 255)
    End Select
    Next
    End Sub

    i have tried this code but gives me a error. the error is this: "Run time error '9' : Subscript out of range"

    can you help?

    thanks

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

    Re: Number of lines of a excel sheet

    VB Code:
    1. For Each c In Worksheets("Sheeet1").Range("A1:A" & Range("A1").End(xlDown).Row).Cells
    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

  6. #6

    Thread Starter
    New Member
    Join Date
    Jun 2006
    Posts
    13

    Re: Number of lines of a excel sheet

    it gives the same error...

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

    Re: Number of lines of a excel sheet

    I see the other error now. Its a misspelled "Sheeet1".
    VB Code:
    1. For Each c In Worksheets("Sheet1").Range("A1:A" & Range("A1").End(xlDown).Row).Cells
    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

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