Results 1 to 48 of 48

How can I speed up the macro I created to delete rows based on text in one of the columns

Threaded View

  1. #1
    Registered User
    Join Date
    06-15-2023
    Location
    Netherlands
    MS-Off Ver
    Office 365
    Posts
    2

    How can I speed up the macro I created to delete rows based on text in one of the columns

    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
    Last edited by 6StringJazzer; 06-15-2023 at 12:09 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Speed up delete rows macro
    By bricksandivy14 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-10-2018, 08:30 AM
  2. Trying to have macro delete rows based on text with merged cells in Column A
    By beepbeep27 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-25-2018, 11:01 AM
  3. [SOLVED] Delete rows based on the list of unique identifiers created
    By Andy308 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-31-2016, 10:52 AM
  4. [SOLVED] Macro to delete rows based in the comparative of the columns between two sheets
    By ricdamiani in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 08-19-2013, 10:37 PM
  5. Macro to delete certain columns and delete rows based on time in another column
    By beepbeep27 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-12-2012, 11:47 AM
  6. Macro to delete rows based on partial text
    By rossi_69 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-09-2009, 06:25 PM
  7. Macro to delete entire rows based values in columns
    By shamade2107 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-13-2009, 11:17 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1