Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Mel Mel is offline
external usenet poster
 
Posts: 74
Default Macro to delete last entry of a column

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!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default Macro to delete last entry of a column

Hi

This should do it:

Sub DeleteRows()
TargetCol = "A"
LastRow = Range(TargetCol & Rows.Count).End(xlUp).Row

Cells(LastRow - 1, TargetCol).Resize(2, 1).ClearContents
End Sub

Regards,
Per

On 6 Feb., 01:34, 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!


  #3   Report Post  
Posted to microsoft.public.excel.programming
CLR CLR is offline
external usenet poster
 
Posts: 594
Default Macro to delete last entry of a column

Maybe this

Sub DeleteBottom2Rows()
ActiveSheet.Select
Range("a65000").Select
Selection.End(xlUp).Select
Selection.EntireRow.Delete
Selection.Offset(-1, 0).EntireRow.Delete
End Sub

hth
Vaya con Dios,
Chuck, CABGx3


"Mel" wrote in message
...
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!



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 62
Default Macro to delete last entry of a column

Hello

This macro will delete the last two entries in the column of your active
cell.
(even if the column is empty, or has only one value in row 1)

Sub Delete_Last_2()

On Error Resume Next
Cells(Rows.Count, ActiveCell.Column).End(xlUp).Offset(-1, 0).ClearContents
On Error GoTo 0
Cells(Rows.Count, ActiveCell.Column).End(xlUp).ClearContents

End Sub








"Mel" a écrit dans le message de groupe de
discussion : ...
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!


  #5   Report Post  
Posted to microsoft.public.excel.programming
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!



  #6   Report Post  
Posted to microsoft.public.excel.programming
CLR CLR is offline
external usenet poster
 
Posts: 594
Default Macro to delete last entry of a column

Sorry, I mis-read your post........this one will delete just the last two
entries in column A, rather than the entire rows.

Sub DeleteBottom2Rows()
ActiveSheet.Select
Range("a65000").Select
Selection.End(xlUp).Select
Selection.ClearContents
Selection.Offset(-1, 0).ClearContents
End Sub

Vaya con Dios,
Chuck, CABGx3




"clr" wrote in message
...
Maybe this

Sub DeleteBottom2Rows()
ActiveSheet.Select
Range("a65000").Select
Selection.End(xlUp).Select
Selection.EntireRow.Delete
Selection.Offset(-1, 0).EntireRow.Delete
End Sub

hth
Vaya con Dios,
Chuck, CABGx3


"Mel" wrote in message
...
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!





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How 2 lock row and column delete/add but allow data entry? CC Santa Monica Excel Discussion (Misc queries) 8 January 29th 19 02:51 AM
Auto entry of data based on entry of text in another column or fie Judy Rose Excel Discussion (Misc queries) 2 May 21st 08 01:14 PM
Search Column - Find Multiple Entries - Sum Then Delete to Single Entry Ledge Excel Programming 5 June 19th 06 08:25 PM
Delete a Column Based on User Entry Anice Excel Programming 3 June 13th 06 02:54 PM
macro to delete entire rows when column A is blank ...a quick macro vikram Excel Programming 4 May 3rd 04 08:45 PM


All times are GMT +1. The time now is 05:16 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"