SpectreHUN

New Member
Joined
Aug 15, 2014
Messages
14
So my problem is that I have 900 lines of code in a Worksheet Change event sub. On my rig, it runs pretty quickly, but on the PC the sheet will be used on, it takes about 2 seconds to run, so from a productivity standpoint, it's not ideal.
What the sub does is it colorcodes the rows based on whether the item has been paid for or not.
I'm pretty new to VBA, so I could only hardcode it, that's why it is so long. What i'm looking for is a way for the sub to be dynamic.
Here is an excerpt of the code for two lines:

Code:
If Not ActiveSheet.Range("B10").Value = "" And Not ActiveSheet.Range("J10").Value = "" Then
ActiveSheet.Unprotect
Rows(10).Interior.Color = RGB(61, 240, 115)
ActiveSheet.Protect , DrawingObjects:=True, Contents:=True, Scenarios:=True
ElseIf Not ActiveSheet.Range("B10").Value = "" And ActiveSheet.Range("J10").Value = "" Then
ActiveSheet.Unprotect
Rows(10).Interior.Color = RGB(240, 61, 79)
ActiveSheet.Protect , DrawingObjects:=True, Contents:=True, Scenarios:=True
Else
ActiveSheet.Unprotect
Rows(10).Interior.ColorIndex = xlNone
ActiveSheet.Protect , DrawingObjects:=True, Contents:=True, Scenarios:=True
End If

If Not ActiveSheet.Range("B13").Value = "" And Not ActiveSheet.Range("J13").Value = "" Then
ActiveSheet.Unprotect
Rows(13).Interior.Color = RGB(61, 240, 115)
ActiveSheet.Protect , DrawingObjects:=True, Contents:=True, Scenarios:=True
ElseIf Not ActiveSheet.Range("B13").Value = "" And ActiveSheet.Range("J13").Value = "" Then
ActiveSheet.Unprotect
Rows(13).Interior.Color = RGB(240, 61, 79)
ActiveSheet.Protect , DrawingObjects:=True, Contents:=True, Scenarios:=True
Else
ActiveSheet.Unprotect
Rows(13).Interior.ColorIndex = xlNone
ActiveSheet.Protect , DrawingObjects:=True, Contents:=True, Scenarios:=True
End If

Any help would be appreciated! :)
 
That's why I said it's ghetto. :D Actually, there is a third option, which i did not consider, it can be blank too.
 
Upvote 0

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Forum statistics

Threads
1,215,756
Messages
6,126,691
Members
449,330
Latest member
ThatGuyCap

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