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

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target = Range("Your Range Here") Then
        Target.Font.ColorIndex = 3
End If
End Sub
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0
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.
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,214,376
Messages
6,119,174
Members
448,870
Latest member
max_pedreira

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