View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Alberto Ast[_2_] Alberto Ast[_2_] is offline
external usenet poster
 
Posts: 181
Default Macro to delete last entry of a column

Let say you data start on cell B3.

Sub deletecell()
Range("b3").Select 'first cell of your column
Selection.End(xlDown).Select 'go all the way down to last used cell
ActiveCell.Offset(-1, 0).Select 'go up one cell
ActiveCell.Resize(2, 1).ClearContents 'increase range 2x1 cell, delete
last two cell
End Sub

Hope it works fine for your needs



"Mel" wrote:

I want to delete the last 2 entries of column of data in excel 2007. The
column length varies each time I want to run the macro. I've tried recording
a macro using the 'ctl down' shortcut then deleting the last two entries.
However, when I run the macro on a different data set it doesn't delete the
last entries but deletes the data in the rows that was recorded in the
original macro.

Please could you advise me on the line of code I need to refer to the last
two entries of a column of any length.

Thank you!