Worksheet Change function

christianbiker

Active Member
Joined
Feb 3, 2006
Messages
365
Is it possible, using the below Private Sub, to set the selection to a range and if anything within that range is modified have the text within that cell or range changed to red?

Private Sub worksheet_change(ByVal target As Range)

Any help would be appreciated,
Thanks
 

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.

Macropheliac

Board Regular
Joined
Aug 26, 2005
Messages
165
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target = Range("Your Range Here") Then
        Target.Font.ColorIndex = 3
End If
End Sub
 

christianbiker

Active Member
Joined
Feb 3, 2006
Messages
365
I have tried the code in a blank worksheet however it is giving me a mismatch 13 error. I am not sure why. I am putting it in the specific worksheet that I want changed.

Private Sub Worksheet_Change(ByVal Target As Range)
If Target = Range("A1:a100") Then
Target.Font.ColorIndex = 10
End If
End Sub
 

Macropheliac

Board Regular
Joined
Aug 26, 2005
Messages
165
Target refers to a single cell. Try this:
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Not Intersect(Target, Range("A1:A100")) Is Nothing Then
        Target.Font.ColorIndex = 3
End If
End Sub
 

christianbiker

Active Member
Joined
Feb 3, 2006
Messages
365
Well that sort of works. It changes every time I click on the cell, even if I don't make any changes which is not what I want. I would like the colour to change only if a value changes within the range specified.
 

Macropheliac

Board Regular
Joined
Aug 26, 2005
Messages
165
My apologies :oops:

Code:
Private Sub Worksheet_Change(ByVal Target As Range) 

If Not Intersect(Target, Range("A1:A100")) Is Nothing Then 
        Target.Font.ColorIndex = 3 
End If 
End Sub
It needs Change instead of Selection Change Event.
 

Forum statistics

Threads
1,137,205
Messages
5,680,174
Members
419,887
Latest member
Vasokir

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