Find last column in excel?

I want find last column ( A,B,C,…)
and assign last row & row 1 in range as below.


Please guide me about it.

Hi @fairymemay

You can read the excel and do this in datatable then re-write the data into excel.

Use read range it will give you Data table variable

then find last row
yourDatatable.Rows(yourDatatable.Rows.Count - 1)

then find last column
yourDatatable(yourDatatable.Columns.Count - 1)

Let me know if you want to do it excel only.

You can use ctrl+end it will move you to last cell of last row and column


@PrankurJoshi I use yourDatatable(yourDatatable.Columns.Count - 1)
output : 4
I want output = D


If you want to write in D3 cell you can write the same thing in datatable only and write it back to excel.

Or else you will have to convert this 4 to excel column name.

This worked for me

After updating the last cell write it back to excel.


1 Like

Hi @fairymemay
I found a similar topic.

You can check if the info helps you.
I have used Convert.ToChar(Convert.ToUInt16("A"c)+3) from that link for a similar situation. You can replace 3 with the code written above for last column.


This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.