+ Reply to Thread
Results 1 to 3 of 3

improve DeleteBlankRows()

  1. #1
    Bucky
    Guest

    improve DeleteBlankRows()

    I was using Pearson's DeleteBlankRows() function, but I found a minor
    issue. The problem is that if your sheet has blank rows at the top,
    they don't get deleted. I believe the problem is that

    Set Rng = ActiveSheet.UsedRange.Rows

    does not include the blank rows at the top (since they are not
    considered "UsedRange"). I think the fix is to modify the Set Rng line
    to include those blank rows. I'm not familiar with the objects and
    properties, so can someone help me come up with the most elegant way to
    do this? Conceptually, this is what I want to do:

    Set Rng = ActiveSheet.(A1 to LastCellOfUsedRange).Rows


    http://www.cpearson.com/excel/deleti...eleteBlankRows


  2. #2
    Ron de Bruin
    Guest

    Re: improve DeleteBlankRows()

    Hi Bucky

    Try this one


    Sub Example1()
    Dim Firstrow As Long
    Dim Lastrow As Long
    Dim Lrow As Long
    Dim CalcMode As Long
    Dim ViewMode As Long

    With Application
    CalcMode = .Calculation
    .Calculation = xlCalculationManual
    .ScreenUpdating = False
    End With

    ViewMode = ActiveWindow.View
    ActiveWindow.View = xlNormalView

    Firstrow = ActiveSheet.UsedRange.Cells(1).Row
    Lastrow = ActiveSheet.UsedRange.Rows.Count + Firstrow - 1

    With ActiveSheet
    .DisplayPageBreaks = False
    For Lrow = Lastrow To 1 Step -1

    If Application.CountA(.Rows(Lrow)) = 0 Then .Rows(Lrow).Delete
    'This will delete the row if the whole row is empty (all columns)

    Next
    End With

    ActiveWindow.View = ViewMode
    With Application
    .ScreenUpdating = True
    .Calculation = CalcMode
    End With

    End Sub


    --
    Regards Ron de Bruin
    http://www.rondebruin.nl


    "Bucky" <[email protected]> wrote in message news:[email protected]...
    >I was using Pearson's DeleteBlankRows() function, but I found a minor
    > issue. The problem is that if your sheet has blank rows at the top,
    > they don't get deleted. I believe the problem is that
    >
    > Set Rng = ActiveSheet.UsedRange.Rows
    >
    > does not include the blank rows at the top (since they are not
    > considered "UsedRange"). I think the fix is to modify the Set Rng line
    > to include those blank rows. I'm not familiar with the objects and
    > properties, so can someone help me come up with the most elegant way to
    > do this? Conceptually, this is what I want to do:
    >
    > Set Rng = ActiveSheet.(A1 to LastCellOfUsedRange).Rows
    >
    >
    > http://www.cpearson.com/excel/deleti...eleteBlankRows
    >




  3. #3
    Bucky
    Guest

    Re: improve DeleteBlankRows()

    Ron de Bruin wrote:
    > Firstrow = ActiveSheet.UsedRange.Cells(1).Row
    > Lastrow = ActiveSheet.UsedRange.Rows.Count + Firstrow - 1


    Thanks, I basically used that idea. But I wanted to keep the rest of
    the code intact, so this is the section that sets the range from A1 to
    the last used cell.

    lastRow = ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Row
    lastCol = ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Column
    Set Rng = ActiveSheet.Range(Cells(1, 1), Cells(lastRow, lastCol))


+ 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