Solved

macro to delete blank empty row set data range

Posted on 2014-01-16
3
654 Views
Last Modified: 2014-01-17
Hi Expert's excel 2007

(starting point a2) and data range a2:g15000 to across columns and rows a2: and delete th3 entire row where the cell are either empty or blank.
0
Comment
Question by:route217
  • 2
3 Comments
 
LVL 27

Expert Comment

by:MacroShadow
ID: 39784827
I'm sorry your question isn't clear please rephrase it.

Do you want to delete the rows only if all cells in the row are blank or also if only one of them is blank?
0
 
LVL 27

Accepted Solution

by:
MacroShadow earned 500 total points
ID: 39784834
Sub DeleteBlankRows1()

'Deletes the entire row within the selection if the ENTIRE row contains no data.

    Dim rng As Range
    Dim i As Long

    Set rng = Range("A2:G15000")

    With Application
        .Calculation = xlCalculationManual
        .ScreenUpdating = False

        For i = rng.Rows.Count To 1 Step -1
            If WorksheetFunction.CountA(rng.Rows(i)) = 0 Then
                rng.Rows(i).EntireRow.Delete
            End If
        Next i

        .Calculation = xlCalculationAutomatic
        .ScreenUpdating = True
    End With

End Sub

Sub DeleteBlankRows2()

    'Deletes the entire row within the range if SOME of the cells within the range contain no data

    Dim rng As Range
    
    Set rng = Range("A2:G15000")
    On Error Resume Next
    rng.EntireRow.SpecialCells(xlBlanks).EntireRow.Delete
    On Error GoTo 0

End Sub

Open in new window

0
 

Author Comment

by:route217
ID: 39785755
Thanks for the feedback and apologies for the late reply. ..internet problems.

Let me test.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now