VBA - Loop: check values in given column; if value = 1 -> delete entire row. Proceed until row no x

mesje

New Member
Joined
Sep 23, 2011
Messages
15
Hello All,

I have a typical PEBKAC due to lack of knowledge about VBA syntax...

I need one simple VBA loop:

1). go to cell U2 and start the following loop:
[start]
-if cell value equals not 1 then delete entire row;
move to next row; end loop at row number X.

It's probably a small thing, but can cause a lot of hapiness ;)

Thank you for your help!
Mesje
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Try

Code:
Sub Test()
Dim LR As Long, i As Long
LR = Range("U" & Rows.Count).End(xlUp).Row
For i = LR To 2 Step -1
    If Range("U" & i).Value <> 1 Then Rows(i).Delete
Next i
End Sub
 
Upvote 0
It seems that you replied before I managed to click 'Submit new therad' button! :)
Thank you very much.

Will give it a go.
:)
 
Upvote 0

Forum statistics

Threads
1,214,905
Messages
6,122,174
Members
449,071
Latest member
cdnMech

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