Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
JD JD is offline
external usenet poster
 
Posts: 7
Default Select last n rows and delete?

I've done a search and nothing quite seems to fit. Basically I merely
want to select the last /n/ rows in a certain column and then delete
those entire rows.
n being four for the forseeable future.

It started looking like this:
//---
Range("B" & Rows.Count).End(xlUp).Select
Selection.Offset(RowOffset:=-3).Select
//---
But anything after doesn't do what I'd want.

I appreciate a suggestion.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Select last n rows and delete?

Hi JD,

Try:

'=============
Public Sub TesterD()

Dim n As Long

n = 4

Cells(Rows.Count, "B").End(xlUp).Offset(n - 1).Resize(n).Delete

End Sub
'<<=============


---
Regards,
Norman



"JD" wrote in message
ups.com...
I've done a search and nothing quite seems to fit. Basically I merely
want to select the last /n/ rows in a certain column and then delete
those entire rows.
n being four for the forseeable future.

It started looking like this:
//---
Range("B" & Rows.Count).End(xlUp).Select
Selection.Offset(RowOffset:=-3).Select
//---
But anything after doesn't do what I'd want.

I appreciate a suggestion.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Select last n rows and delete?

Hi JD,

Correcting, try:

'=============
Public Sub TesterD()

Dim n As Long

n = 4

Cells(Rows.Count, "B").End(xlUp).Offset(1 - n). _
Resize(n).EntireRow.Delete
End Sub
'<<=============


--
Regards,
Norman


  #4   Report Post  
Posted to microsoft.public.excel.programming
JD JD is offline
external usenet poster
 
Posts: 7
Default Select last n rows and delete?

Norman Jones wrote:
Hi JD,

Correcting, try:

'=============
Public Sub TesterD()

Dim n As Long

n = 4

Cells(Rows.Count, "B").End(xlUp).Offset(1 - n). _
Resize(n).EntireRow.Delete
End Sub
'<<=============


That one works perfectly, thanks. Question; the resize works as a range
because the variable n has been declared?

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Select last n rows and delete?

Hi JD,

That one works perfectly, thanks. Question; the resize works as a range
because the variable n has been declared?


The Resize Property returns a resized range.

The syntax for Resize is RangeExpression(RowSize, ColumnSize).

The suggested code uses an abbreviated form, Resize(n), which leaves the
ColumnSize of the range unchanged.


---
Regards,
Norman



"JD" wrote in message
oups.com...
Norman Jones wrote:
Hi JD,

Correcting, try:

'=============
Public Sub TesterD()

Dim n As Long

n = 4

Cells(Rows.Count, "B").End(xlUp).Offset(1 - n). _

Resize(n).EntireRow.Delete
End Sub
'<<=============


That one works perfectly, thanks. Question; the resize works as a range
because the variable n has been declared?



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
Select a range of rows to delete Donna[_3_] Excel Worksheet Functions 2 January 26th 10 07:32 PM
select and delete specific rows Paulg Excel Discussion (Misc queries) 1 August 22nd 06 04:12 PM
select and delete all blank rows Bill from UniqueAuction.com Excel Discussion (Misc queries) 1 October 11th 05 09:06 PM
Delete every 3rd row, then delete rows 2-7, move info f/every 2nd row up one to the end and delete the row below Annette[_4_] Excel Programming 2 September 21st 04 02:40 PM
Select certain rows of sheet & delete the rest Steve Wylie Excel Programming 2 January 9th 04 07:16 PM


All times are GMT +1. The time now is 05:43 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"