For i = X To 1 Step -1
If Worksheets("Sheet1").Range("B" & i).Value = "" Then Worksheets("Sheet1").Rows(i).Delete
Next i
Sub t()
Dim i As Long, lc As Long
lc = ActiveSheet.Cells.Find("*", , xlValues, xlPart, xlByColumns, xlPrevious).Column
With ActiveSheet
For i = .Cells(Rows.Count, 2).End(xlUp).Row To 1 Step -1
If Application.CountA(.Cells(i, 1).Resize(, lc)) = lc - 1 Then
If .Cells(i, 2).Value = "" Then Rows(i).Delete
End If
Next
End With
End Sub
The OP indicates that if column B is blank and another cell in the row is blank then you do not want to delete that row. Delete if column B is the only blank cell in the row. To do that it has to be assumed that all rows are of equal length.
Code:Sub t() Dim i As Long, lc As Long lc = ActiveSheet.Cells.Find("*", , xlValues, xlPart, xlByColumns, xlPrevious).Column With ActiveSheet For i = .Cells(Rows.Count, 2).End(xlUp).Row To 1 Step -1 If Application.CountA(.Cells(i, 1).Resize(, lc)) = lc - 1 Then If .Cells(i, 2).Value = "" Then Rows(i).Delete End If Next End With End Sub
JLGWhiz The idea would be to have it only base the decision to delete based on the contents of column B so if the cell in column B in that row was blank it would delete it. If there was data in it, it would leave the row unchanged
JLGWhiz, good call on that. Two changes to your code:
1. .Rows(i).Delete
2. Next i
You were missing the first period for #1, and i for #2.
For i = 1 To 3
For j = 1 To 4
For x = 1 To 12
MsgBox i + j
Next 'belongs to x
Next 'belongs to j
Next 'belongs to i
Regarding "For i = X to 1" - You'll need to change X to whatever your last row is. Change the 1 to whatever your first row is.
Change:
Worksheets("Sheet1")
To:
Worksheets("YourSheetName")
Sub t2()
Dim i As Long
With ActiveSheet
.Range("B2", .Cells(Rows.Count, 2)).End(xlUp).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
End With
End Sub