PDA

View Full Version : Finding last cell in a column



loloobaloo
06-23-2022, 02:10 AM
Hi friends I am going to write a Function in VBA that I should have first cell and last cell in a column. the first is easy but I don't know how I can do it for the last cell.
I don't know what should I write instead of x in the lastCell.
I hope you can help me

firstCell = Cells(1, 1)
lastCell = Cells(x, 1)

georgiboy
06-23-2022, 02:40 AM
Something like:

Sub test()
Dim FirstCell As Range
Dim LastCell As Range

Set FirstCell = Cells(1, 1)
Set LastCell = Cells(Rows.Count, 1).End(xlUp)

Range(FirstCell, LastCell).Select
End Sub

snb
06-23-2022, 02:51 AM
Sub M_snb()
sn = sheet1.cells(1).currentregion
msgbox sheet1.cells(ubound(sn),1)
End Sub