|
-
Jun 8th, 2006, 04:54 AM
#1
Thread Starter
New Member
[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.
-
Jun 8th, 2006, 05:02 AM
#2
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:
Sheet1.UsedRange.End(xlDown).row
Sheet1.UsedRange.End(xlToRight).Column
'Or
Sheet1.Cells.SpecialCells(xlCellTypeLastCell).Row
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Jun 8th, 2006, 05:22 AM
#3
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
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...
-
Jun 8th, 2006, 06:20 AM
#4
Thread Starter
New Member
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
-
Jun 8th, 2006, 06:23 AM
#5
Re: Number of lines of a excel sheet
VB Code:
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Jun 8th, 2006, 06:26 AM
#6
Thread Starter
New Member
Re: Number of lines of a excel sheet
it gives the same error...
-
Jun 8th, 2006, 06:29 AM
#7
Re: Number of lines of a excel sheet
I see the other error now. Its a misspelled "Sheeet1".
VB Code:
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|