VBA code taking about 40 minutes to run - why?!

Nachlawi

New Member
Joined
Oct 11, 2017
Messages
3
Hi,

I have this code:
Code:
    For rw = 2 To num
    Application.StatusBar = String(3, ChrW(9609)) & "Scrubbing at row " & rw & "/" & num & "."
        If InStr(Range("L" & rw).Value, "1") > 0 Then
            Range("A" & rw).Value = "#"
            Range("K" & rw).Value = "#"
            Range("M" & rw).Value = "#"
        End If
        If InStr(Range("L" & rw).Value, "2") > 0 Then
            Range("A" & rw).Value = "#"
            Range("K" & rw).Value = "#"
            Range("M" & rw).Value = "#"
        End If
        If InStr(Range("L" & rw).Value, "3") > 0 Then
            Range("A" & rw).Value = "#"
            Range("K" & rw).Value = "#"
            Range("M" & rw).Value = "#"
        End If
        If InStr(Range("L" & rw).Value, "11") > 0 Then
            Range("A" & rw).Value = "#"
            Range("K" & rw).Value = "#"
            Range("M" & rw).Value = "#"
        End If
        If InStr(Range("L" & rw).Value, "23") > 0 Then
            Range("A" & rw).Value = "#"
            Range("K" & rw).Value = "#"
            Range("M" & rw).Value = "#"
        End If
        If InStr(Range("L" & rw).Value, "39") > 0 Then
            Range("A" & rw).Value = "#"
            Range("K" & rw).Value = "#"
            Range("M" & rw).Value = "#"
        End If


        If Range("E" & rw).Value = "" Then
            Range("E" & rw).ClearContents
        End If
        If Range("F" & rw).Value = "" Then
            Range("F" & rw).ClearContents
        End If
        If Range("G" & rw).Value = "" Then
            Range("G" & rw).ClearContents
        End If
        If Range("H" & rw).Value = "" Then
            Range("H" & rw).ClearContents
        End If
        If Range("I" & rw).Value = "" Then
            Range("I" & rw).ClearContents
        End If
        If Range("J" & rw).Value = "" Then
            Range("J" & rw).ClearContents
        End If
    Next rw

The first part is going through certain cells and scrubbing data if a certain condition is met. The second part is clearing the contents of blank cells so that the COUNT function works properly with those cells. However, this code takes really long to loop through the 300+rows (about 40 mins). Is there a way that I can speed this up :confused:

Thanks
 
What is the name of the procedure that is running this code?
How is it being called?
Do you have any other VBA code in your workbook, specifically any Event Procedure code?

(pretty much what Norie asked here):
How is the code being executed?

Do you have any other code that this code could be triggering, e.g. sheet event code?
This information is critical to figuring out what might be going on. You might have other code interfering, or might be caught in a loop because of how your code is structured. But we will not be able to say until we know the answer to these questions.
 
Last edited:
Upvote 0

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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