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

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

Scott Huish

MrExcel MVP
Joined
Mar 17, 2004
Messages
19,961
Office Version
  1. 365
Platform
  1. Windows
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

Evagrius Ponticus

Well-known Member
Joined
May 24, 2007
Messages
1,467
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

Evagrius Ponticus

Well-known Member
Joined
May 24, 2007
Messages
1,467
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,191,557
Messages
5,987,269
Members
440,087
Latest member
Ruppert23

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
Top