Clean up Code.....Running slow

JaredMcCullough

Well-known Member
Joined
Aug 1, 2011
Messages
516
Been a while....I threw this together real quick it gets the job done but processes kinda slow was wondering if anyone could streamline it so it doesnt have a delay in processing

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim cell As Range
lRow = Range("F" & Rows.Count).End(xlUp).Row
Set MR = Range("F4:F" & lRow)
    For Each cell In MR
    
    If cell.Value = "NIS" Then Cells(cell.Row, "A").Interior.Color = vbYellow
    
    If cell.Value = "F" Then Cells(cell.Row, "A").Interior.Color = vbRed
    
    If cell.Value = "LR" Then Cells(cell.Row, "A").Interior.Color = vbGreen
    
    If cell.Value = "A" Then Cells(cell.Row, "A").Interior.Color = vbWhite
    
    If cell.Value = "B" Then Cells(cell.Row, "A").Interior.Color = vbWhite
    
    If cell.Value = "C" Then Cells(cell.Row, "A").Interior.Color = vbWhite
    
    If cell.Value = "D" Then Cells(cell.Row, "A").Interior.Color = vbWhite
    Next cell
   
    
    For Each cell In Range("O4:U5000")
 
        If cell.Value = "P" Then
            cell.Interior.Color = vbGreen
        End If
        If cell.Value = "F" Then
            cell.Interior.Color = vbRed
        End If
        
        If cell.Value = "" Then
            cell.Interior.Color = vbWhite
        End If
    Next cell
End Sub
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Code:
with application.
.screenupdating = false
.enableevents = false
end with

before your code, then reverse the false to true when the code ends, or you could just create CFs for the columns (bear in mind there are a million rows now, so )
 
Last edited:
Upvote 0
In addition to mole999's suggestion.

Worksheet.Change Event (Excel)

Insert
Code:
If Target.Column = 6 Then

Instead of this
Code:
If cell.Value = "A" Then Cells(cell.Row, "A").Interior.Color = vbWhite
If cell.Value = "B" Then Cells(cell.Row, "A").Interior.Color = vbWhite
If cell.Value = "C" Then Cells(cell.Row, "A").Interior.Color = vbWhite
If cell.Value = "D" Then Cells(cell.Row, "A").Interior.Color = vbWhite

you could use this
Code:
If cell.Value = "A" Or cell.Value = "B" Or cell.Value = "C" Or Cell.Value = "D" Then Cells(cell.Row, "A").Interior.Color = vbWhite
Don't know if that'll make it any faster though

Code:
For Each cell In Range("O4:U5000")    '<----- Why 5000?
If your last value is in cell R4750 you are checking 7 x 250 empty cells just for the heck of it.
 
Upvote 0

Forum statistics

Threads
1,222,437
Messages
6,166,023
Members
452,008
Latest member
Customlogoflipflops

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