I have an excel sheet in which I need to find the last non empty cell in a specific row.
How do I do this?
The below will select this for me, but it will select the first not empty cell, I need the last not empty cell in the row #29.
Worksheets("DTCs").Range("A29").End(xlToRight).Select
Best Answer
I have expanded on my comment above to provide solutions that
Select
The
Find
method in the second code is a far more direct method of establishing the first non-blank cellThis line
Set rng1 = ws.Rows(1).Find("*", ws.[a1], xlValues, , xlByColumns, xlPrevious)
says, start in cell A1 of Sheet "DTCa" then look backwards (ie from the last cell in row 1) in row1 by column looking for anything (the*
). This method either find the last non blank or returnsNothing
, ie an empty rowusing
xltoLeft
with specific checksrecommended