Find the last row of a column and the last column of a row using a macro in an excel report

This macro shows a basic concept of how to find the last row/column. In this form, it is not very useful, at least for me, but customizing it, it is totally useful. In the other hand, in this other topic Know the last column letter of a row using a macro in an excel report, I explain how to find the letter of the last column of a row.

formula excel


When I use the macro ?

For instance, I need to find the last column then the last cell of this same column because all cells in this range are formulas so it will copy and paste this range to the next column.


How to create the macro ?

Read How to create, edit, hide and select a macro in an excel report


How to create the button to associate it with the macro ?

Read How to create a button and associated it to a macro in an excel report


How is the macro ?

Copy the code below and paste it into your macro. You will see my comments in green if exist so follow the help to adapt to your need.

Sub test()
Dim lastRow As Long
Dim lastCol As Long
' searching the last row of the column A represented by the number 1
lastRow = Cells(Rows.Count, 1).End(xlUp).Row
' searching the last column of the row 1
lastCol = Cells(1, Columns.Count).End(xlToLeft).Column
' a popup message will display to tell you the results
MsgBox "Last Row: " &lastRow & vbNewLine & "Last Column: " & lastCol
End Sub

Interesting Management