Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6370837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:58:54+00:00 2026-05-25T00:58:54+00:00

I have the following code: Excel.Range range = workSheet.UsedRange; for (rowCount = 2; rowCount

  • 0

I have the following code:

Excel.Range range = workSheet.UsedRange;
for (rowCount = 2; rowCount <= range.Rows.Count; rowCount++)
  {
     //Do something here
  }

However, I encounter the following problem. If I have the following excel data:

cell1, cell2, cell3

cell4, cell5, cell6

..............cell7

range.Rows.Count will return 3. However, I don’t care about column C – it has some data that is used for drop-down lists within say column 1. How can I get the range.Rows.Count only for columns A and B?

For example:
enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T00:58:55+00:00Added an answer on May 25, 2026 at 12:58 am

    Assuming there are no blanks in column A, just walk down rows until you hit a blank row using range.Offset(x,y): (sorry, I’m more fluent with Excel VBA, you’ll have to translate to C#)

    Dim myCell as Range
    set myCell = workSheet.Range("A2");
    Do Until myCell.Formula = ""
         'Do something here
         set myCell = myCell.Offset(1,0) 'Moves down a row 
    Loop
    

    Or just loop through numerically using Worksheet.Cells(row,col):

    Dim myRow as Integer
    myRow = 2
    Do Until cells(myrow,2).Formula = ""
         'Do something here
         myRow = myRow + 1
    Loop
    

    Edit: You could also use Range("A1").End(xlDown) to find the last populated cell of the first column. This should work with your current logic. Something like (I’ll try it in C#):

    Excel.Range range = workSheet.Range("A1", Range("A1").End(xlDown));
    for (rowCount = 2; rowCount <= range.Rows.Count; rowCount++)
      {
         //Do something here
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have got the following code from here to read an Excel file using
I have something of the following : Sheet 1 (Name Range : Code) Column
I have the following code section, designed to count how many Excel processes are
I have the following routine that dumps a DataTable into an Excel worksheet. private
I have the following code to export a gridview to excel and the export
I have the following code to open Excel template file and save it as
C# or VB.NET suggestion are welcome. I have the following code to create Excel
I have the following code to protect the sheets of a workbook in Excel
I have the following code: [Thank you Mike Rosenblum!] using System; using Microsoft.Office.Interop.Excel; using
I have the following VBA code inside an Excel macro: With ActiveSheet.QueryTables.Add( _ Connection:=ConnStr,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.