Slow macro wasting time

redmanYJ

New Member
Joined
Sep 10, 2008
Messages
3
I'm trying to run code to color in some cells in a row based on the value they contain. The following code works but it takes too much time to recalculate all 106,500 cells every time you change a value. I need to have it run through a worksheet change event. Is there anyway to have it only recalculate the cell range in the row that I'm changing instead of all 740 rows each time I change a cell?
eg. If I change G20, it would only need it to recalculate N20:EY20. Or if I change F234, it would only recalculate N234:EY234 etc.

Dim spot As Range
For Each spot In Range("N10:EY750")
spot.Interior.ColorIndex = spot.Value
Next
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Hello and welcome to MrExcel.

Try this. Right click the sheet tab, select View Code and paste in

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim spot As Range
For Each spot In Range("N" & Target.Row & ":EY" & Target.Row)
    spot.Interior.ColorIndex = spot.Value
Next spot
End Sub
 
Upvote 0
Try

Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)
Dim spot As Range
If Target.Row < 10 Then Exit Sub
For Each spot In Range("N" & Target.Row & ":EY" & Target.Row)
    spot.Interior.ColorIndex = spot.Value
Next spot
End Sub
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,120
Members
451,399
Latest member
alchavar

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