Macro, Unexpected Results

Desu Nota from Columbus

Well-known Member
Joined
Mar 17, 2011
Messages
556
I wrote this macro:

Code:
Sub FAKE()
Dim i As Integer

Application.ScreenUpdating = False
With Sheets("SDIC")
    For i = 16 To 350
        If Range("L" & i).Value = False Then
            Range("A" & i & ":" & "L" & i).Delete (xlUp)
        End If
    Next i
    
 End With
 Application.ScreenUpdating = True
 
End Sub
In column L, starting at row 16 I have this formula

Code:
=SUMPRODUCT(--($S$16:$S$253=C16),--($T$16:$T$253=D16))>0
Which returns a true or false.

I would like the macro to delete range(A-L) for any row that this above formula returns false.

For some reason this did not happen with the above macro and I am not sure why.

I expect that once the macro is run, all the results will have a True in column L (which did not happen)
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
I think your code is not deleting the rows you want because you're using With Sheets("SDIC") and then evaluating Range("L" & i), it should be .Range("L" & i) it's how WITH works..

A simple solution is to change your code to:
Code:
Sub FAKE()
Dim i As Integer

Application.ScreenUpdating = False
With Sheets("SDIC")
    For i = 350 to 16 Step -1
        If .Range("L" & i) = False Then .Range("A" & i & ":" & "L" & i).Delete 
    Next i
    
 End With
 Application.ScreenUpdating = True
 
End Sub
Although if you have no data after column L, then may be easier to delete the entire row, i.e.
Code:
If .Range("L" & i) = False Then .Rows(i).EntireRow.Delete
 
Upvote 0
I will try this solution when I can and let you know how it goes.

I agree that it is much easier to delete the entire row, but I have data that cannot be deleted in subsequent columns.

Thanks for the help.
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,831
Members
452,947
Latest member
Gerry_F

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