Delete empty whole row if range B:I doesn't contain data.

hurcuma

New Member
Joined
Oct 19, 2017
Messages
12
Hi

I have a spreadsheet that contains the following.

ABCDEFGHI
1Staff ID12345567892345676535554888873334642223
2Last NameJonesSmithBriggsTownsendDaleStoneLavellTrigg
3FirstnameAndrewMaryJamesTaniaChipDaleRichardBeth
4Start Date01/11/1710/11/1714/11/1716/11/1718/01/17
5Pay GradeG1G1G2G1G3G3G4G1
6Phone Type
7Address typeHome

Work
8Comp1000800600200400500
9Bonus100100100100

<tbody>
</tbody>

Could someone help me work out how I can get excel to review the contents of the table, from Cols B to I.
Then within that range if the rest of the row doesn't contain data, then delete the whole of that row.

So in this example above, Row 6 would disappear.

My "live" spreadsheet has 121 rows, but not all of them have data in, so I want to extract only those that have data.

Many thanks in advance for any help.
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Try:
Code:
Sub delRows()
    Application.ScreenUpdating = False
    Dim LastRow As Long
    LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    Dim x As Long
    For x = LastRow To 2 Step -1
        If WorksheetFunction.CountA(Range("B" & x & ":I" & x)) = 0 Then
            Rows(x).EntireRow.Delete
        End If
    Next x
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Hi Mumps.

that is amazing, it works perfect, I have been searching google for several days.

Could I ask one extra question
The actual file is a download from our hr database, and it populates each employee either a starter or a change, so one month you might go to Column I then next month it could be Column AJ etc.

The first column to look in will always be Col B. But as the last column could vary is there a way to amend the vba code to the last entry in Row 2?

Regards
 
Upvote 0
Here you go!
Code:
Sub delRows()
    Application.ScreenUpdating = False
    Dim LastRow As Long
    LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    Dim lColumn As Long
    lColumn = ActiveSheet.Cells(2, Columns.Count).End(xlToLeft).Column
    Dim x As Long
    For x = LastRow To 2 Step -1
        If WorksheetFunction.CountA(Range(Cells(x, 2), Cells(x, lColumn))) = 0 Then
            Rows(x).EntireRow.Delete
        End If
    Next x
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Hi Mumps.

Thank you for coming back with a solution so quick once more, but I can't seem to get the second vba that you have posted to work where it is looking for the last cell in row 2 to work.

After inserting the macro, and running it, no effect is happening, the original data stays in tact.

Any thoughts?

and many thanks again for your help.
 
Upvote 0
See if this macro works for you...
Code:
[table="width: 500"]
[tr]
	[td]Sub DeleteBlankDataRows()
  Dim LastRow As Long, ColCount As String
  LastRow = Cells(Rows.Count, "A").End(xlUp).Row
  ColCount = Cells.Find("*", , xlFormulas, , xlByColumns, xlPrevious).Column - 1
  Range("A1:A" & LastRow) = Evaluate(Replace(Replace("IF(COUNTBLANK(OFFSET(A1:A%,ROW(A1:A%)-1,1,1,@))=@,""#N/A"",A1:A%)", "@", ColCount), "%", LastRow))
  On Error GoTo NoBlankRows
  Columns("A").SpecialCells(xlConstants, xlErrors).EntireRow.Delete
NoBlankRows:
End Sub[/td]
[/tr]
[/table]
 
Upvote 0
Hi Rick, thank you for taking a look at my problem.

Once running your macro, I am getting no rows deleted.

Mumps VBA works great, and I wondered as a simple next step is it possible for me to just visually look at the last column and then run the macro and a pop says enter last column e.g. AJ and then continue with rest of the macro?
 
Upvote 0
Hi Rick

Yes, my last column has a countblank formula in each cell.
I can do without this column if that helps.

Other than that, all the cells are without formulas.
 
Upvote 0
Maybe:
Code:
Sub delRows()
    Application.ScreenUpdating = False
    Dim LastRow As Long
    LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    Dim response As String
    response = InputBox("Please enter the last column.")
    Dim x As Long
    For x = LastRow To 2 Step -1
        If WorksheetFunction.CountA(Range(Cells(x, 2), Cells(x, response))) = 0 Then
            Rows(x).EntireRow.Delete
        End If
    Next x
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,793
Messages
6,121,617
Members
449,039
Latest member
Mbone Mathonsi

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