Finding the last empty row, excluding header

Viewed 43

I've got the following column in a table

enter image description here

and I've got the following code

   lrow2 = Cells(Rows.Count, 25).End(xlUp).Row      
      
   Range_to_delete = "Y2:Y" & lrow2
                             
   Range(Range_to_delete).Clear

My problem right now is that sometimes there are no numbers on column Y, therefore when that code executes it deletes the header too, is there a way I can modify the following line of code so that it excludes row 1 somehow?

lrow2 = Cells(Rows.Count, 25).End(xlUp).Row  

Note: I can't say if lrow2 = 1 then skip this part because then that messes up some of my other conditions that I use later on.

1 Answers

If you don't have any values, you don't need to delete anything. So maybe this can work:

   lrow2 = Cells(Rows.Count, 25).End(xlUp).Row      
   
   If lrow2 > 1 Then 
       Range_to_delete = "Y2:Y" & lrow2
                             
       Range(Range_to_delete).Clear
   End if
Related