Avatar of Flora Edwards
Flora Edwards
Flag for Sweden

asked on 

what should be the best correct option to use SpecialCells(xlCellTypeLastCell) or Find * or rows.count?

I am new with in this VBA world.

still learning.

i am confused a bit with the different methods used to find the last row or last column of a specific sheet.

which one should i use?  what is the pros and cons of each of the below methods?
which one of them is more robust so that it will not miss anything?

'Using Find Function
  LastRow = sht.Cells.Find("*", searchorder:=xlByRows, searchdirection:=xlPrevious).Row

Open in new window


'Using SpecialCells Function
  LastRow = sht.Cells.SpecialCells(xlCellTypeLastCell).Row

Open in new window


'Ctrl + Shift + End
  LastRow = sht.Cells(sht.Rows.Count, "A").End(xlUp).Row

Open in new window

VBAMicrosoft ExcelMicrosoft Office

Avatar of undefined
Last Comment
Flora Edwards

8/22/2022 - Mon