Delete Entire Rows if Whole Range is Blank

AsifShah

Board Regular
Joined
Feb 12, 2021
Messages
70
Office Version
  1. 2016
  2. 2013
Platform
  1. Windows
Hello Friends

I have a Data in Sheet2,
My Data infomation
Row A1:D1>>> School & Date Information
Row E1:DA1 >> Class Name
Row E2:DA2 >> Book Name
Now iam coping data Sheet2 to an other sheet11 by Class Name Wise, Class name Coding work fine and Blank row Deleting Work Fine .
Problem is that my Delete Blank Rows code is to long . Can any Friend do code short and work fast,

Thanks in Advance


VBA Code:
Private Sub cGetData_Click()
On Error Resume Next
Sheet11.Range("E:T").Clear

Dim arx, ary, fm
Sheet2.Range("A:D").Copy Sheet11.Range("A:D")

arx = Array("Nursery Class", "KG Class", "One Class", "Two Class", "Three Class", "Four Class", "Five Class", "Six Class", "Saven Class", "Eight Class", "Nine Class")
ary = Array("E:F", "G:L", "M:V", "X:AD", "AE:AP", "AQ:AZ", "BA:BJ", "BK:BS", "BT:CB", "CC:CK", "CL:DA")

    fm = Application.Match(ComboBox5.Value, arx, 0)
    If IsNumeric(fm) Then Sheet2.Range(ary(fm - 1)).Copy Sheet11.Range("E1")
'
'Delete Rows
 Dim lngLastRow As Long
    Dim lngMyRow As Long
    Dim xlnCalcMethod As XlCalculation
    
    With Application
        .ScreenUpdating = False
        xlnCalcMethod = .Calculation
        .Calculation = xlCalculationManual
    End With
    
    lngLastRow = Range("A:L").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    

    For lngMyRow = lngLastRow To 3 Step -1
        If Len(Range("E" & lngMyRow)) = 0 And Len(Range("F" & lngMyRow)) = 0 _
        And Len(Range("G" & lngMyRow)) = 0 And Len(Range("H" & lngMyRow)) = 0 _
        And Len(Range("I" & lngMyRow)) = 0 And Len(Range("J" & lngMyRow)) = 0 _
        And Len(Range("K" & lngMyRow)) = 0 And Len(Range("L" & lngMyRow)) = 0 _
        And Len(Range("M" & lngMyRow)) = 0 And Len(Range("N" & lngMyRow)) = 0 _
        And Len(Range("O" & lngMyRow)) = 0 And Len(Range("P" & lngMyRow)) = 0 _
        And Len(Range("Q" & lngMyRow)) = 0 And Len(Range("R" & lngMyRow)) = 0 _
        And Len(Range("S" & lngMyRow)) = 0 And Len(Range("T" & lngMyRow)) = 0 Then
            Rows(lngMyRow).EntireRow.Delete
        End If
    Next lngMyRow
    
    With Application
        .Calculation = xlnCalcMethod
        .ScreenUpdating = True
    End With
End Sub
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
I think you should be able to delete this whole section:
VBA Code:
    For lngMyRow = lngLastRow To 3 Step -1
        If Len(Range("E" & lngMyRow)) = 0 And Len(Range("F" & lngMyRow)) = 0 _
        And Len(Range("G" & lngMyRow)) = 0 And Len(Range("H" & lngMyRow)) = 0 _
        And Len(Range("I" & lngMyRow)) = 0 And Len(Range("J" & lngMyRow)) = 0 _
        And Len(Range("K" & lngMyRow)) = 0 And Len(Range("L" & lngMyRow)) = 0 _
        And Len(Range("M" & lngMyRow)) = 0 And Len(Range("N" & lngMyRow)) = 0 _
        And Len(Range("O" & lngMyRow)) = 0 And Len(Range("P" & lngMyRow)) = 0 _
        And Len(Range("Q" & lngMyRow)) = 0 And Len(Range("R" & lngMyRow)) = 0 _
        And Len(Range("S" & lngMyRow)) = 0 And Len(Range("T" & lngMyRow)) = 0 Then
            Rows(lngMyRow).EntireRow.Delete
        End If
    Next lngMyRow
with this:
VBA Code:
    Dim rng As Range
    For lngMyRow = lngLastRow To 3 Step -1
        Set rng = Range("E" & lngMyRow & ":T" & lngMyRow)
        If Application.CountA(rng) = 0 Then Rows(lngMyRow).Delete
    Next lngMyRow
 
Upvote 0
Solution
I think you should be able to delete this whole section:
VBA Code:
    For lngMyRow = lngLastRow To 3 Step -1
        If Len(Range("E" & lngMyRow)) = 0 And Len(Range("F" & lngMyRow)) = 0 _
        And Len(Range("G" & lngMyRow)) = 0 And Len(Range("H" & lngMyRow)) = 0 _
        And Len(Range("I" & lngMyRow)) = 0 And Len(Range("J" & lngMyRow)) = 0 _
        And Len(Range("K" & lngMyRow)) = 0 And Len(Range("L" & lngMyRow)) = 0 _
        And Len(Range("M" & lngMyRow)) = 0 And Len(Range("N" & lngMyRow)) = 0 _
        And Len(Range("O" & lngMyRow)) = 0 And Len(Range("P" & lngMyRow)) = 0 _
        And Len(Range("Q" & lngMyRow)) = 0 And Len(Range("R" & lngMyRow)) = 0 _
        And Len(Range("S" & lngMyRow)) = 0 And Len(Range("T" & lngMyRow)) = 0 Then
            Rows(lngMyRow).EntireRow.Delete
        End If
    Next lngMyRow
with this:
VBA Code:
    Dim rng As Range
    For lngMyRow = lngLastRow To 3 Step -1
        Set rng = Range("E" & lngMyRow & ":T" & lngMyRow)
        If Application.CountA(rng) = 0 Then Rows(lngMyRow).Delete
    Next lngMyRow
Joe Thanks Alot..... Code working excellent.
 
Upvote 0
I think you should be able to delete this whole section:
VBA Code:
    For lngMyRow = lngLastRow To 3 Step -1
        If Len(Range("E" & lngMyRow)) = 0 And Len(Range("F" & lngMyRow)) = 0 _
        And Len(Range("G" & lngMyRow)) = 0 And Len(Range("H" & lngMyRow)) = 0 _
        And Len(Range("I" & lngMyRow)) = 0 And Len(Range("J" & lngMyRow)) = 0 _
        And Len(Range("K" & lngMyRow)) = 0 And Len(Range("L" & lngMyRow)) = 0 _
        And Len(Range("M" & lngMyRow)) = 0 And Len(Range("N" & lngMyRow)) = 0 _
        And Len(Range("O" & lngMyRow)) = 0 And Len(Range("P" & lngMyRow)) = 0 _
        And Len(Range("Q" & lngMyRow)) = 0 And Len(Range("R" & lngMyRow)) = 0 _
        And Len(Range("S" & lngMyRow)) = 0 And Len(Range("T" & lngMyRow)) = 0 Then
            Rows(lngMyRow).EntireRow.Delete
        End If
    Next lngMyRow
with this:
VBA Code:
    Dim rng As Range
    For lngMyRow = lngLastRow To 3 Step -1
        Set rng = Range("E" & lngMyRow & ":T" & lngMyRow)
        If Application.CountA(rng) = 0 Then Rows(lngMyRow).Delete
    Next lngMyRow
Dear Joe , is there any code for listbox columns base on Sheet columns
Sheet11 Columns show in Listbox bcoz Class wise every time Sheets 11 Columns are changed. as you seen in code every time columns count are different.
thanks in advance
 
Upvote 0
Dear Joe , is there any code for listbox columns base on Sheet columns
Sheet11 Columns show in Listbox bcoz Class wise every time Sheets 11 Columns are changed. as you seen in code every time columns count are different.
thanks in advance
That is a whole different question, and should be posted in a new thread,
 
Upvote 0

Forum statistics

Threads
1,215,072
Messages
6,122,966
Members
449,094
Latest member
Anshu121

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top