If cell is non-blank then delete row

Sontauzo

New Member
Joined
Mar 13, 2018
Messages
18
Hello,

I am using the code below to try to remove rows that contain any value in a certain column (Column AK). Presently, the code is deleting every line. I am probably missing something really obvious, but i have looked on several different sites and I can't seem to sort it out.

Any help would be greatly appreciated.

Variable p is a particular worksheet that is declared earlier in the code

For t = t To 1 Step -1
If p.Cells(t, "AK") = "" Then
Else
p.Rows(t).EntireRow.Delete
End If
Next

BWL
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Please add code tags around your code.
Code:
Sub Maybe()
Dim sh As Worksheet, i As Long, lr As Long
    Set sh = Worksheets("Sheet3")    '<----- Change as required
    lr = sh.Cells(Rows.Count, "AK").End(xlUp).Row
        With sh
            For i = lr To 1 Step -1
                If .Cells(i, 37) <> "" Then .Cells(i, 37).EntireRow.Delete Shift:=xlUp
            Next i
        End With
End Sub
 
Upvote 0
Thank you for the the suggestion, and my apologies for not tagging the code properly. However, macro that you included still deletes all rows. I tried running it initially in the context of the larger Macro that i am running and then as a stand alone and the results were the same both times.
 
Upvote 0
Do the so called empty cells have a space in it so they appear empty but in reality are not?
Obviously, they are not empty.
Put this in a cell a few columns away and pull down to cover your range.
Code:
=Len(AK1)
See what the result is.
 
Upvote 0
try this on a copy of your file

Code:
Sub DeleteRows()

    Application.ScreenUpdating = False

    With Range("T:T")
        .Replace "*", True, xlWhole
        .SpecialCells(xlCellTypeConstants, 4).EntireRow.Delete
    End With

    Application.ScreenUpdating = True

End Sub

hth,
Ross
 
Last edited:
Upvote 0
Do the so called empty cells have a space in it so they appear empty but in reality are not?
Obviously, they are not empty.
Put this in a cell a few columns away and pull down to cover your range.
Code:
=Len(AK1)
See what the result is.

Thank you for this suggestion. It turns out there was a space in each cell. I was able to remove that from the report and use my original code. Thanks again!
 
Upvote 0
Glad you have it all sorted.
Thanks for letting us know and good luck
 
Upvote 0

Forum statistics

Threads
1,214,924
Messages
6,122,294
Members
449,077
Latest member
Rkmenon

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