PC Review


Reply
Thread Tools Rate Thread

Change event and ranges

 
 
=?Utf-8?B?Sm9obiBLZWl0aA==?=
Guest
Posts: n/a
 
      7th Mar 2007
An area on my worksheet is used to build a VLookup table of holidays. I have
a button that will re-sort the table. I have the code bleow that will change
the color of the cell with the date when it is entered. Also the button
changes text & color based on if a new sort will be needed...

I am getting a type mismatch error when I select an area (that intersects
one of my date cells). How can I handle this to prevent errors? or how do I
test for erasing an area and only go into the change color code when I am
processing the cell(s) of an area that intersect?

Private Sub Worksheet_Change(ByVal Target As Range)
Dim isect As Range
Set isect = Application.Intersect(Target, ActiveSheet.Range("e6:e50"))
If Not isect Is Nothing Then
If Len(Target.Value) > 0 Then
Target.Interior.ColorIndex = 3 'Cell background red
Set_SortButton ("Red")
Target.Select
Else
Target.Interior.ColorIndex = xlColorIndexNone
End If
End If
End Sub

--
Regards,
John
 
Reply With Quote
 
 
 
 
=?Utf-8?B?SmltIFRob21saW5zb24=?=
Guest
Posts: n/a
 
      7th Mar 2007
I'm not too sure that I followed the question 100% but give ths a wirl...

Private Sub Worksheet_Change(ByVal Target As Range)
Dim isect As Range
Dim rng As Range

Set isect = Application.Intersect(Target, ActiveSheet.Range("e6:e50"))
If Not isect Is Nothing Then
For Each rng In isect
If Len(rng.Value) > 0 Then
Target.Interior.ColorIndex = 3 'Cell background red
'Set_SortButton ("Red")
Target.Select
Else
rng.Interior.ColorIndex = xlColorIndexNone
End If
Next rng
End If
End Sub
--
HTH...

Jim Thomlinson


"John Keith" wrote:

> An area on my worksheet is used to build a VLookup table of holidays. I have
> a button that will re-sort the table. I have the code bleow that will change
> the color of the cell with the date when it is entered. Also the button
> changes text & color based on if a new sort will be needed...
>
> I am getting a type mismatch error when I select an area (that intersects
> one of my date cells). How can I handle this to prevent errors? or how do I
> test for erasing an area and only go into the change color code when I am
> processing the cell(s) of an area that intersect?
>
> Private Sub Worksheet_Change(ByVal Target As Range)
> Dim isect As Range
> Set isect = Application.Intersect(Target, ActiveSheet.Range("e6:e50"))
> If Not isect Is Nothing Then
> If Len(Target.Value) > 0 Then
> Target.Interior.ColorIndex = 3 'Cell background red
> Set_SortButton ("Red")
> Target.Select
> Else
> Target.Interior.ColorIndex = xlColorIndexNone
> End If
> End If
> End Sub
>
> --
> Regards,
> John

 
Reply With Quote
 
=?Utf-8?B?Sm9obiBLZWl0aA==?=
Guest
Posts: n/a
 
      7th Mar 2007
Thanks Jim.
For each rng in isect...
was exactly the syntax i was looking for.
--
Regards,
John


"Jim Thomlinson" wrote:

> I'm not too sure that I followed the question 100% but give ths a wirl...
>
> Private Sub Worksheet_Change(ByVal Target As Range)
> Dim isect As Range
> Dim rng As Range
>
> Set isect = Application.Intersect(Target, ActiveSheet.Range("e6:e50"))
> If Not isect Is Nothing Then
> For Each rng In isect
> If Len(rng.Value) > 0 Then
> Target.Interior.ColorIndex = 3 'Cell background red
> 'Set_SortButton ("Red")
> Target.Select
> Else
> rng.Interior.ColorIndex = xlColorIndexNone
> End If
> Next rng
> End If
> End Sub
> --
> HTH...
>
> Jim Thomlinson
>
>
> "John Keith" wrote:
>
> > An area on my worksheet is used to build a VLookup table of holidays. I have
> > a button that will re-sort the table. I have the code bleow that will change
> > the color of the cell with the date when it is entered. Also the button
> > changes text & color based on if a new sort will be needed...
> >
> > I am getting a type mismatch error when I select an area (that intersects
> > one of my date cells). How can I handle this to prevent errors? or how do I
> > test for erasing an area and only go into the change color code when I am
> > processing the cell(s) of an area that intersect?
> >
> > Private Sub Worksheet_Change(ByVal Target As Range)
> > Dim isect As Range
> > Set isect = Application.Intersect(Target, ActiveSheet.Range("e6:e50"))
> > If Not isect Is Nothing Then
> > If Len(Target.Value) > 0 Then
> > Target.Interior.ColorIndex = 3 'Cell background red
> > Set_SortButton ("Red")
> > Target.Select
> > Else
> > Target.Interior.ColorIndex = xlColorIndexNone
> > End If
> > End If
> > End Sub
> >
> > --
> > Regards,
> > John

 
Reply With Quote
 
Jon Peltier
Guest
Posts: n/a
 
      7th Mar 2007
To be safe, you should probably use

For Each rng In isect.Cells

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
http://PeltierTech.com
_______


"John Keith" <(E-Mail Removed)> wrote in message
news:EAE5EDEC-F9E1-42EC-85EF-(E-Mail Removed)...
> Thanks Jim.
> For each rng in isect...
> was exactly the syntax i was looking for.
> --
> Regards,
> John
>
>
> "Jim Thomlinson" wrote:
>
>> I'm not too sure that I followed the question 100% but give ths a wirl...
>>
>> Private Sub Worksheet_Change(ByVal Target As Range)
>> Dim isect As Range
>> Dim rng As Range
>>
>> Set isect = Application.Intersect(Target, ActiveSheet.Range("e6:e50"))
>> If Not isect Is Nothing Then
>> For Each rng In isect
>> If Len(rng.Value) > 0 Then
>> Target.Interior.ColorIndex = 3 'Cell background red
>> 'Set_SortButton ("Red")
>> Target.Select
>> Else
>> rng.Interior.ColorIndex = xlColorIndexNone
>> End If
>> Next rng
>> End If
>> End Sub
>> --
>> HTH...
>>
>> Jim Thomlinson
>>
>>
>> "John Keith" wrote:
>>
>> > An area on my worksheet is used to build a VLookup table of holidays.
>> > I have
>> > a button that will re-sort the table. I have the code bleow that will
>> > change
>> > the color of the cell with the date when it is entered. Also the
>> > button
>> > changes text & color based on if a new sort will be needed...
>> >
>> > I am getting a type mismatch error when I select an area (that
>> > intersects
>> > one of my date cells). How can I handle this to prevent errors? or
>> > how do I
>> > test for erasing an area and only go into the change color code when I
>> > am
>> > processing the cell(s) of an area that intersect?
>> >
>> > Private Sub Worksheet_Change(ByVal Target As Range)
>> > Dim isect As Range
>> > Set isect = Application.Intersect(Target,
>> > ActiveSheet.Range("e6:e50"))
>> > If Not isect Is Nothing Then
>> > If Len(Target.Value) > 0 Then
>> > Target.Interior.ColorIndex = 3 'Cell background red
>> > Set_SortButton ("Red")
>> > Target.Select
>> > Else
>> > Target.Interior.ColorIndex = xlColorIndexNone
>> > End If
>> > End If
>> > End Sub
>> >
>> > --
>> > Regards,
>> > John



 
Reply With Quote
 
=?Utf-8?B?Q3VydA==?=
Guest
Posts: n/a
 
      10th Mar 2007
first time for multiple triggers.
this seems to be what I want. Can it be modified to specify conditions for
many cells in a row to run event? do not know if you can have multiple
conditions for event trigger
thanks

"John Keith" wrote:

> Thanks Jim.
> For each rng in isect...
> was exactly the syntax i was looking for.
> --
> Regards,
> John
>
>
> "Jim Thomlinson" wrote:
>
> > I'm not too sure that I followed the question 100% but give ths a wirl...
> >
> > Private Sub Worksheet_Change(ByVal Target As Range)
> > Dim isect As Range
> > Dim rng As Range
> >
> > Set isect = Application.Intersect(Target, ActiveSheet.Range("e6:e50"))
> > If Not isect Is Nothing Then
> > For Each rng In isect
> > If Len(rng.Value) > 0 Then
> > Target.Interior.ColorIndex = 3 'Cell background red
> > 'Set_SortButton ("Red")
> > Target.Select
> > Else
> > rng.Interior.ColorIndex = xlColorIndexNone
> > End If
> > Next rng
> > End If
> > End Sub
> > --
> > HTH...
> >
> > Jim Thomlinson
> >
> >
> > "John Keith" wrote:
> >
> > > An area on my worksheet is used to build a VLookup table of holidays. I have
> > > a button that will re-sort the table. I have the code bleow that will change
> > > the color of the cell with the date when it is entered. Also the button
> > > changes text & color based on if a new sort will be needed...
> > >
> > > I am getting a type mismatch error when I select an area (that intersects
> > > one of my date cells). How can I handle this to prevent errors? or how do I
> > > test for erasing an area and only go into the change color code when I am
> > > processing the cell(s) of an area that intersect?
> > >
> > > Private Sub Worksheet_Change(ByVal Target As Range)
> > > Dim isect As Range
> > > Set isect = Application.Intersect(Target, ActiveSheet.Range("e6:e50"))
> > > If Not isect Is Nothing Then
> > > If Len(Target.Value) > 0 Then
> > > Target.Interior.ColorIndex = 3 'Cell background red
> > > Set_SortButton ("Red")
> > > Target.Select
> > > Else
> > > Target.Interior.ColorIndex = xlColorIndexNone
> > > End If
> > > End If
> > > End Sub
> > >
> > > --
> > > Regards,
> > > John

 
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
Worksheet Change event on different ranges with data validation Savalou Dave Microsoft Excel Programming 2 6th Mar 2009 10:46 PM
Referring to Ranges in Change-Event Macro? =?Utf-8?B?V3VkZHVz?= Microsoft Excel Misc 4 24th Aug 2007 08:12 PM
Auto sorting multiple ranges on event rlutes Microsoft Excel Programming 2 17th Jun 2005 04:52 AM
is there any event like worhsheet_change for ranges? Abhinav Microsoft Excel Programming 3 13th May 2004 12:26 PM
Event validating two ranges with dates G R E G Microsoft Excel Programming 1 9th Aug 2003 12:03 AM


Features
 

Advertising
 

Newsgroups
 


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