I don’t know how to get the last row number which has data in a Excel file. Like below sample ,vacant rows are included .
Without typing any function into the file.It’s because typing any data into Excel is not allowed by my client.
Read Range activity will let you store all this data into a table which then you can get the count and last row. From my understanding, if you use “” as your range it will take the first row with data so if there are blank rows at the start, it will skip them. However, yours is starting on the first row so that shouldn’t be a problem.
To get the last row in this case, you can use .Rows.Count
So if dt is your datatable variable stored from using the Read Range with range of “”, dt.Rows.Count
You can verify the correct value with a Message Box or Write Line
If for some reason the vacant rows are not included, try using a complete range in the Read Range like “A1:H1000”
I tried
1.Read Range with range of “” (output dt)
2.assign inLastRow = dt.Rows.Count
3.Write Line inLastRow.Tostring
But 1 minused number was showed.
When the Excel sheet has 10 rows,inLastRow showed 9
When I checked AddHeaders excuting Read Range , inLastRow showed 8 (even minus1)
Just for your understanding. In Datatable index starts from 0 and in excel it starts from 1.
Now if header of excel are added then. Datable index 0 will be equal to excel row 2.
And if header is not added then Datable index 0 will be equal to excel row 1.
As index of excel sheet and data table are started with 1 and 0 respectively. This will need to read last row data from table.rows.count - 1 (since start index is 0) .
PDI Steps to achieve
Use Read Range Activity
set input: SheetName=“your sheet”, Range=“” (this must be empty to read all value from sheet),
set output: yourDataTable
AddHeaders: Checked (First row of excel sheet become header for yourDataTable)
Use Assign Activity
rCount (this is your row counter)= yourDataTable.Rows.Count
Write Line Activity
yourDataTable.Rows(rcount-1)(0).ToString (this write First cell value of last row in output pan)
@oitot,
If it showed no number or letter and did not show an error, then the last row has nothing in the first column. You might need to verify that there’s data there, and also look at what rcount-1 is because that will tell you which row it is looking at.