1

I am using below code to read excel file: I want to print only first row data, for that I require to find no of rows in sheet (non blank) .

Set xlBook = GetObject(FilePath)
xlBook.Application.Visible = True
xlBook.Windows(1).Visible = True
xlBook.Application.WindowState = xlMinimized

Dim irow As Integer

For irow = 2 To 101
    MsgBox xlBook.Worksheets(1).Cells(irow, 1).Value
Next
2
  • Are you trying to count only used rows (non empty rows) in excel sheet? Commented Sep 20, 2012 at 9:02
  • Yes I want to count used rows. Commented Sep 20, 2012 at 9:15

1 Answer 1

1

Unfortunately I will not recommend UsedRange.

Two reasons

  1. UsedRange will not give you no of rows in sheet (non blank) as you want it.
  2. UsedRange is highly unreliable. If you want to find the last row then see this link . Please note that this will still not give you number of NON Blank Rows.

To get the number of Non Blank Rows, you will have to use AutoFilter. Use <>"" as the autofilter criteria and then use the visible cells rows count to get the non blank rows.

Edit:

See this link

This post deletes all columns which are empty apart from a specific header. I am sure you can modify it to suit your needs.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.