Rows.Count.ToString cannot get correct count in Excel

Hi, I used “K2:M”+DT.Rows.Count.ToString in the “Select Range” activity to select the required range in Excel. My data table DT has 3 rows excluding header, so ideally it should select range K2:M4. However, when I run the process, it only selects K2:M3 instead. I have no idea why this happened. Please help me with it! Thank you!

Give a try on following
"K2:M"+(DT.Rows.Count +1).ToString

Yes it works now! But may I know why did this happen if my data table is properly formatted and there are no empty entries. As I need to do a manual slides, so I may have to explain why I am using count+1.

As far i do understand your situationin

  • Excel you got 4 rows 1 Header row, 3 Data rows
  • Datatable has a Count of 3 aß the Data rows are Count
    So WE have to add the Offset of 1 to get to the Last Excel row

I see… Thank you very much! :slightly_smiling_face: