Finding a Cell that meets a condition

hyoung3

New Member
Joined
May 9, 2011
Messages
21
Have a data set that is very large. One field is populated with time values. I want to delete all rows up to a certain time value (ie. any row with time value < 11:00). I have used a while loop with an imbedded IF THEN statement that will delete rows as the condition is tested but it takes way too long. I was wondering if there was a way to find the address of the first cell that meets my condition and delete all rows that do not. Thanks.
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Welcome to the board.

I don't have time to provide the full code (as I'm about to go home!) but this is something I use a lot and saved in my personal folder:
Code:
Sub DeleteVisibleRows()
With Application
    .DisplayAlerts = False
    .ScreenUpdating = False
    .Calculation = xlCalculationManual
End With
ActiveSheet.UsedRange.Offset(1, 0).Resize(ActiveSheet.UsedRange.Rows.Count - 1).Rows.Delete
ActiveSheet.AutoFilterMode = False
With Application
    .DisplayAlerts = True
    .ScreenUpdating = True
    .Calculation = xlCalculationAutomatic
End With
End Sub
Assuming the data is already filtered, it deletes everything that is visible, except the header row; I've not included the filter part as it gives me the flexibility to use on any sheet when I filter and I don't know in advance which column I'm filtering by.

Perhaps you can apply a filter for all values less than 11:00 and then use above?

A slight change to above is to use the special cell types and visible cells only, a quick bit of searching online and you should be able to find this.

Good luck,
Jack
 
Upvote 0

Forum statistics

Threads
1,224,517
Messages
6,179,239
Members
452,898
Latest member
Capolavoro009

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