mjay Posted June 22, 2005 Posted June 22, 2005 Hello and greetings. I hope this will be a simple question for most but is causing me grief. I am trying to find out the number of rows in an Excel spreadsheet. I am using vb.net. The code compiles beautifully but everytime I run the program it returns the row number to be 1. I know there are more than 1 rows on this spreadsheet. What am I doing wrong. Here is part of my code msgbox (ws.UsedRange.Rows.Count) ' just so I see how many rows are returned For i = 1 to ws.UsedRange.Rows.Count 'then I loop through the rows to get a specific column next i Thanks mjay Quote
herilane Posted June 28, 2005 Posted June 28, 2005 find out the number of rows in an Excel spreadsheet The number of rows in an Excel spreadsheet is always 65,536... I assume you are actually trying to get the number of used rows? UsedRange might return a single row if you enter data only in, say, cell A5 and don't touch A1:A4 (no formatting, no data). Rows 1 to 4 would then not count as used. Have you checked ws.UsedRange.Address - does that offer any clues? Have you checked that ws is the right worksheet? For any more specific help, I think you'll have to post a sample workbook that's causing trouble, and more of the code that you're using. Quote
Recommended Posts