PC Review


Reply
Thread Tools Rate Thread

change event for cells within a range

 
 
MJKelly
Guest
Posts: n/a
 
      6th Nov 2008

Hi,

I want to run a macro if a cell within a certain range is changed by a
user.

eg, if a cell is changed within the range A1:A10 then the text color
of that cell changes from black to red.

can you help?

The only code I have so far is:-



Private Sub Worksheet_Change(ByVal Target As Range)

Target = Range("A1:A10")

End Sub

kind regards,
Matt
 
Reply With Quote
 
 
 
 
Mike H
Guest
Posts: n/a
 
      6th Nov 2008
Hi,

Try this

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A1:A10")) Is Nothing Then
Target.Font.ColorIndex = 3
End If
End Sub

Mike

"MJKelly" wrote:

>
> Hi,
>
> I want to run a macro if a cell within a certain range is changed by a
> user.
>
> eg, if a cell is changed within the range A1:A10 then the text color
> of that cell changes from black to red.
>
> can you help?
>
> The only code I have so far is:-
>
>
>
> Private Sub Worksheet_Change(ByVal Target As Range)
>
> Target = Range("A1:A10")
>
> End Sub
>
> kind regards,
> Matt
>

 
Reply With Quote
 
MJKelly
Guest
Posts: n/a
 
      6th Nov 2008
Mike,

That worked a treat. One further query, I want to paste data to the
range during a weekly setup. And do not want the event to trigger
until this has been done. How can I not have the event triggered in
this instance? The idea being that the original data is in grey text
and not bold and the amendments to the data are Black/Bold.

code now reads:-

Private Sub Worksheet_Change(ByVal Target As Range)

If Not Intersect(Target, Range("A1:A10", "C1:C10")) Is Nothing Then
With Target
.Font.ColorIndex = 1
.Font.Bold = True
End With
End If

End Sub

Thanks,
Matt
 
Reply With Quote
 
Mike H
Guest
Posts: n/a
 
      6th Nov 2008
Hi,

If your pasting data then the chances are your pasting multiple cells so
this as a first line would work

If Target.Cells.Count > 1 Then Exit Sub

On the other hand a 100% catch all would be to modify the code thus

If Not Intersect(Target, Range("A1:A10", "C1:C10")) Is Nothing Then
response = MsgBox("Process Bolding?", vbYesNo)
If response = vbNo Then Exit Sub
With Target
.Font.ColorIndex = 1
.Font.Bold = True
End With
End If

End Sub

Mike


"MJKelly" wrote:

> Mike,
>
> That worked a treat. One further query, I want to paste data to the
> range during a weekly setup. And do not want the event to trigger
> until this has been done. How can I not have the event triggered in
> this instance? The idea being that the original data is in grey text
> and not bold and the amendments to the data are Black/Bold.
>
> code now reads:-
>
> Private Sub Worksheet_Change(ByVal Target As Range)
>
> If Not Intersect(Target, Range("A1:A10", "C1:C10")) Is Nothing Then
> With Target
> .Font.ColorIndex = 1
> .Font.Bold = True
> End With
> End If
>
> End Sub
>
> Thanks,
> Matt
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
change colors in a range of excel cells based on another range of cells Bobbi Muck Microsoft Excel Programming 1 9th Apr 2010 03:47 AM
RE: Lock or Unlock Range of Cells on Worksheet_Change Event Mike H Microsoft Excel Worksheet Functions 0 13th Jul 2008 05:29 PM
Change Event Range Help mastermind Microsoft Excel Programming 3 30th Mar 2006 01:30 PM
Change Event on a named range GregR Microsoft Excel Programming 2 12th Jul 2005 09:37 PM
Copy cells into range of cells until cell change =?Utf-8?B?bWRlYW5kYQ==?= Microsoft Excel Worksheet Functions 1 22nd Apr 2005 08:41 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:24 PM.