+ Reply to Thread
Results 1 to 5 of 5

Select last n rows and delete?

  1. #1
    JD
    Guest

    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. #2
    Norman Jones
    Guest

    Re: 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" <[email protected]> wrote in message
    news:[email protected]...
    > 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. #3
    Norman Jones
    Guest

    Re: 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. #4
    JD
    Guest

    Re: 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. #5
    Norman Jones
    Guest

    Re: 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" <[email protected]> wrote in message
    news:[email protected]...
    > 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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1