+ Reply to Thread
Results 1 to 2 of 2

Delete a range of rows above blank cell

Hybrid View

  1. #1
    Registered User
    Join Date
    07-26-2008
    Location
    Canada
    Posts
    3

    Delete a range of rows above blank cell

    does anybody know the code that would delete a range of rows that lie directly above a blank row (or cell)

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello d_rock90,

    You need to know two things: the address of the blank row or cell, and the number of rows or cells to be deleted.

    This example deletes the bottom 5 cells and rows on a worksheet. Column "A" is used to determine the last row on the active sheet.
    Sub DeleteRowsAbove()
      
      Dim LastRow As Long
      Dim N As Long
      Dim Rng As Range
    
        LastRow = Cells(Rows.Count, "A").End(xlUp).Row
        N = LastRow - N + 1   'Number of cells or rows to be deleted
    
         'Use this code to Delete Cells
          Set Rng = Range(Cells(N, "A"), Cells(LastRow, "A"))
            Rng.Delete Shift:=xlShiftUp
    
         'Use this code to Delete Rows
          Set Rng = Range(Rows(N), Rows(LastRow))
            Rng.EntireRow.Delete Shift:=xlShiftUp
    
    End Sub

+ 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