excel - First used row in my selected column -


i want clear cells in worksheet first used last used row in selected column, first must know first used row in selected column. how can find first row in "x" column? (x may = {a, b, c, ...})

try

firstusedrow = worksheets("sheet1").cells(1, 1).end(xldown).row 

where second argument in cells(1, 1) column number (e.g., a=1, b=2, etc.). sheet1 worksheet name of worksheet in question.

it possible, though unlikely in case, first row row 1. in case, above code select last row of used range. safety measure case, identify last row , make sure first row either 1 or row generated above code. so

finalrow = worksheets("sheet1").cells(worksheets("sheet1").usedrange.rows.count, 1).end(xlup).row if finalrow = firstusedrow     firstusedrow = 1 end if 

all together

firstusedrow = worksheets("sheet1").cells(1, 1).end(xldown).row finalrow = worksheets("sheet1").cells(worksheets("sheet1").usedrange.rows.count, 1).end(xlup).row if finalrow = firstusedrow     firstusedrow = 1 end if 

Comments