Bomino
Member
Hello,
I have been digging/Googling for couple of hours for a possible easy solution to my problem. I have a worksheet with couple of 100K rows and I woud like to purge out ALL the rows that do NOT contain a certain text. I've found Ron's code http://www.rondebruin.nl/win/s4/win001.htm
and tweak it a little.....but it is taking for ever to run. Here is the code:
Could someone please help with a faster code?
Thank you.
I have been digging/Googling for couple of hours for a possible easy solution to my problem. I have a worksheet with couple of 100K rows and I woud like to purge out ALL the rows that do NOT contain a certain text. I've found Ron's code http://www.rondebruin.nl/win/s4/win001.htm
and tweak it a little.....but it is taking for ever to run. Here is the code:
Code:
Sub Loop_Example()
Dim Firstrow As Long
Dim Lastrow As Long
Dim Lrow As Long
Dim CalcMode As Long
Dim ViewMode As Long
Dim inputData As String
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
'We use the ActiveSheet but you can replace this with
'Sheets("MySheet")if you want
With ActiveSheet
'We select the sheet so we can change the window view
.Select
'If you are in Page Break Preview Or Page Layout view go
'back to normal view, we do this for speed
ViewMode = ActiveWindow.View
ActiveWindow.View = xlNormalView
'Turn off Page Breaks, we do this for speed
.DisplayPageBreaks = False
inputData = InputBox("Enter Text to Keep:", "Input Box Text")
'Set the first and last row to loop through
Firstrow = .UsedRange.Cells(1).Row
Lastrow = .UsedRange.Rows(.UsedRange.Rows.Count).Row
'We loop from Lastrow to Firstrow (bottom to top)
For Lrow = Lastrow To Firstrow Step -1
' Delete each row if the inputData value does NOT exist in the row (It will look in the whole row)
If Application.CountIf(.Rows(Lrow), inputData) > 0 Then .Rows(Lrow).Delete
Next Lrow
End With
ActiveWindow.View = ViewMode
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With
End Sub
Thank you.