Hi all,
I am new on the forum, so lets start with an introduction. I am Dennis, living in the Netherlands (sorry for my ((d)english ) and working as a data analist. One of the tools I use is excel and I using VBA/Macro's to make my life a bit easier.
At the moment I have created a Macro to delete some rows on tab named "check" when the text in column "I" is not in column "E" at the tab named "B". The Macro is working but it is very slow, due too the large amount of data. Tab "check" haves 100k rows and after the macro 50% will be deleted after running the macro. Tab "B" have 50 rows, so the discision to keep the data is based on 50 factors. I already paused screen updates and calculation to speedup the performance.
See the code bellow, can anybody advise how I can make it faster?
Thanks for your help!
Sub SettingCheck()
Dim wb As Workbook
Dim ws As Worksheet
Dim wsBeFeed As Worksheet
Dim lastRow1 As Long
Dim lastRow2 As Long
Dim rng1 As Range
Dim rng2 As Range
Dim cell As Range
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Set wb = ThisWorkbook
Set ws = wb.Worksheets("Check")
Set wsB = wb.Worksheets("B")
lastRow1 = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
lastRow2 = wsB.Cells(wsB.Rows.Count, "A").End(xlUp).Row
Set rng1 = ws.Range("I2:I" & lastRow1)
Set rng2 = wsB.Range("E2:E" & lastRow2)
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
For Each cell In rng1
If WorksheetFunction.CountIf(rng2, cell.Value) = 0 Then
cell.EntireRow.Delete
End If
Next cell
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub
Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #2 requires code tags. I have added them for you this time because you are a new member. --6StringJazzer
Bookmarks