PC Review


Reply
Thread Tools Rate Thread

Changing the background color of a cell

 
 
Steve
Guest
Posts: n/a
 
      9th Nov 2009
Hi

I'm comparing two lists and if a contract number equals that on another list
I want to highlight the line in the original list. I have looked for ages on
the web but everywhere that uses the range command seems to assume you know
the row but I'm trying to use two variables as below.

If Trim(Worksheets("Cappuchino Data").Cells(iCappuchinoRow,
7).Value) = Trim(Worksheets("Subs Safety Net").Cells(iSubsSafetyRow,
3).Value) Then

Worksheets("Cappuchino Data").Range(Cells(iCappuchinoRow, 1),
Cells(iCappuchinoRow, 31)).Interior.Color = 1
GoTo NextCappLine

End If

However, this just throws up an error.

Can you please help?

Many Thanks

Steve
 
Reply With Quote
 
 
 
 
Jarek Kujawa
Guest
Posts: n/a
 
      9th Nov 2009
if Excel 2003 then change

Color

to

ColorIndex

On 9 Lis, 11:49, Steve <St...@discussions.microsoft.com> wrote:
> Hi
>
> I'm comparing two lists and if a contract number equals that on another list
> I want to highlight the line in the original list. I have looked for ageson
> the web but everywhere that uses the range command seems to assume you know
> the row but I'm trying to use two variables as below.
>
> * * * * If Trim(Worksheets("Cappuchino Data").Cells(iCappuchinoRow,
> 7).Value) = Trim(Worksheets("Subs Safety Net").Cells(iSubsSafetyRow,
> 3).Value) Then
>
> * * * * * * Worksheets("Cappuchino Data").Range(Cells(iCappuchinoRow, 1),
> Cells(iCappuchinoRow, 31)).Interior.Color = 1
> * * * * * * GoTo NextCappLine
>
> * * * * End If
>
> However, this just throws up an error.
>
> Can you please help?
>
> Many Thanks
>
> Steve


 
Reply With Quote
 
Jacob Skaria
Guest
Posts: n/a
 
      9th Nov 2009
Hi Steve

The below code will highlight each row if 'Cappuchino Data' column G data
match with the list in Subs Safety Net").Range("C1:C10")..Try and feedback

Sub Macro()

Dim rng1 As Range, rng2 As Range, cell As Range

Set rng1 = Worksheets("Cappuchino Data").Range("G1:G10")
Set rng2 = Worksheets("Subs Safety Net").Range("C1:C10")

For Each cell In rng1
If Trim(cell.Text) <> "" Then
If Not rng2.Find(cell.Text, , xlValues, 1) Is Nothing Then
cell.Offset(0, -6).Resize(1, 31).Interior.ColorIndex = 15
End If
End If
Next

End Sub

If this post helps click Yes
---------------
Jacob Skaria


"Steve" wrote:

> Hi
>
> I'm comparing two lists and if a contract number equals that on another list
> I want to highlight the line in the original list. I have looked for ages on
> the web but everywhere that uses the range command seems to assume you know
> the row but I'm trying to use two variables as below.
>
> If Trim(Worksheets("Cappuchino Data").Cells(iCappuchinoRow,
> 7).Value) = Trim(Worksheets("Subs Safety Net").Cells(iSubsSafetyRow,
> 3).Value) Then
>
> Worksheets("Cappuchino Data").Range(Cells(iCappuchinoRow, 1),
> Cells(iCappuchinoRow, 31)).Interior.Color = 1
> GoTo NextCappLine
>
> End If
>
> However, this just throws up an error.
>
> Can you please help?
>
> Many Thanks
>
> Steve

 
Reply With Quote
 
Steve
Guest
Posts: n/a
 
      9th Nov 2009
Hi

Many thanks for your response and help

Yes it does seem to have worked (i just need to confirm), however, my only
question is, I don't always know the length of each of the lists so I can't
put the range in. In this instance, I changed the values but it would be nice
to have a generic routine that will work for any lists.

I havea routine that returns the number of lines in a list so using that
would be good.

Many Thanks

Steve

"Steve" wrote:

> Hi
>
> I'm comparing two lists and if a contract number equals that on another list
> I want to highlight the line in the original list. I have looked for ages on
> the web but everywhere that uses the range command seems to assume you know
> the row but I'm trying to use two variables as below.
>
> If Trim(Worksheets("Cappuchino Data").Cells(iCappuchinoRow,
> 7).Value) = Trim(Worksheets("Subs Safety Net").Cells(iSubsSafetyRow,
> 3).Value) Then
>
> Worksheets("Cappuchino Data").Range(Cells(iCappuchinoRow, 1),
> Cells(iCappuchinoRow, 31)).Interior.Color = 1
> GoTo NextCappLine
>
> End If
>
> However, this just throws up an error.
>
> Can you please help?
>
> Many Thanks
>
> Steve

 
Reply With Quote
 
Jacob Skaria
Guest
Posts: n/a
 
      9th Nov 2009
Steve

You can set that as
Set rng1 = Worksheets("Cappuchino Data").Range("G:G")
Set rng2 = Worksheets("Subs Safety Net").Range("C:C")

OR using named range

Set rng1 = Worksheets("Cappuchino Data").Range("namedrange1")
Set rng2 = Worksheets("Subs Safety Net").Range("namedrange2")



If this post helps click Yes
---------------
Jacob Skaria


"Steve" wrote:

> Hi
>
> Many thanks for your response and help
>
> Yes it does seem to have worked (i just need to confirm), however, my only
> question is, I don't always know the length of each of the lists so I can't
> put the range in. In this instance, I changed the values but it would be nice
> to have a generic routine that will work for any lists.
>
> I havea routine that returns the number of lines in a list so using that
> would be good.
>
> Many Thanks
>
> Steve
>
> "Steve" wrote:
>
> > Hi
> >
> > I'm comparing two lists and if a contract number equals that on another list
> > I want to highlight the line in the original list. I have looked for ages on
> > the web but everywhere that uses the range command seems to assume you know
> > the row but I'm trying to use two variables as below.
> >
> > If Trim(Worksheets("Cappuchino Data").Cells(iCappuchinoRow,
> > 7).Value) = Trim(Worksheets("Subs Safety Net").Cells(iSubsSafetyRow,
> > 3).Value) Then
> >
> > Worksheets("Cappuchino Data").Range(Cells(iCappuchinoRow, 1),
> > Cells(iCappuchinoRow, 31)).Interior.Color = 1
> > GoTo NextCappLine
> >
> > End If
> >
> > However, this just throws up an error.
> >
> > Can you please help?
> >
> > Many Thanks
> >
> > Steve

 
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
Changing Cell Background Color based on data from another cell Speedy Microsoft Excel Misc 2 16th Mar 2009 04:10 PM
changing cell background color =?Utf-8?B?b2tlbGJlcw==?= Microsoft Excel Worksheet Functions 1 20th Sep 2006 03:28 PM
Changing background color based on different cell djarcadian Microsoft Excel Misc 3 10th Aug 2006 10:44 PM
Macro for Changing Cell Background Color RSummersJr@gmail.com Microsoft Excel Programming 7 2nd Dec 2005 05:39 PM
automatically changing the background color of a cell =?Utf-8?B?bWFydGlu?= Microsoft Excel Programming 8 6th Jan 2005 11:00 AM


Features
 

Advertising
 

Newsgroups
 


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