Help With Small Code . .

Evagrius Ponticus

Well-known Member
Joined
May 24, 2007
Messages
1,467
Hi,

This code works once only - where did I go wrong?

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
With Range("X16:AQ5000")
If (Range("E7") = "" Or Range("E8") = "") Then
.Font.ColorIndex = 40
Else
.Font.ColorIndex = 1
End If
End With
End Sub
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
What do you mean it only works once? It seemed to work fine for me, although you don't need VBA to do this, it can be done in Conditional Formatting.
 
Upvote 0
well, I've already maxed my conditional formating - for some reason I keep getting an error if I activate cell e7 or e8? "Unable to set the color/index property of the font class."
 
Upvote 0
This is what I have now,


Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Intersect(Target, Range("e7:e8,x16:AQ5000")) Is Nothing Then Exit Sub

With Range("X16:AQ5000")
If (Range("E7") = "" Or Range("E8") = "") Then
 ActiveSheet.Unprotect "7ptcnc"
.Font.ColorIndex = 40
Else
.Font.ColorIndex = 1
 ActiveSheet.Protect "7ptcnc"
End If
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,050
Messages
6,122,868
Members
449,097
Latest member
dbomb1414

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