PC Review


Reply
Thread Tools Rate Thread

Changing Cell Color based upon value on another worksheet

 
 
DPelletier
Guest
Posts: n/a
 
      5th Nov 2009
I need help cell coloring based upon matching data on 2 sheets.

'Sheet1' - Data Dump
'Sheet2' - New Formatting

'Sheet1' column AD = "No" then find value on same row but in Column B
Then search on 'Sheet2' for that value in Column B. If found, color
the field in the row above it Red (Color.Index = 3)

I need to check each row of column AD on 'Sheet1' for value = "No" and
search all fields on 'Sheet2' for the value in Column B of same row.
The colored cell on 'Sheet2' will always in the the same column but 1
row up.

Thank you for any assistance you can provide.

Dwayne P.
 
Reply With Quote
 
 
 
 
JLGWhiz
Guest
Posts: n/a
 
      5th Nov 2009
If I understood the parameters correctly, this should work. You can rename
the sheets to suit in the Set statements.

Sub colorNo()
Dim sh1 As Worksheet, sh2 As Worksheet, fStr As Variant
Dim lr1 As Long, rng As Range, fRng As Range
Set sh1 = Sheets("Sheet1")
Set sh2 = Sheets("Sheet2")
lr1 = sh1.Cells(Rows.Count, "AD").End(xlUp).Row

Set rng = sh1.Range("AD2:AD" & lr1)
For Each c In rng
If c.Value = "No" Then
fStr = sh1.Range("B" & c.Row).Value
With sh2
Set fRng = .UsedRange.Find(fStr, LookIn:=xlValues,
LookAt:=xlWhole)
If Not fRng Is Nothing Then
fAddr = fRng.Address
Do
fRng.Offset(-1).Interior.ColorIndex = 3

Set fRng = .UsedRange.FindNext(fRng)

Loop While Not fRng Is Nothing And fRng.Address <> fAddr
End If
End With
End If
Next
End Sub




"DPelletier" <(E-Mail Removed)> wrote in message
news:5f3ab4f9-0587-45a9-b2c2-(E-Mail Removed)...
>I need help cell coloring based upon matching data on 2 sheets.
>
> 'Sheet1' - Data Dump
> 'Sheet2' - New Formatting
>
> 'Sheet1' column AD = "No" then find value on same row but in Column B
> Then search on 'Sheet2' for that value in Column B. If found, color
> the field in the row above it Red (Color.Index = 3)
>
> I need to check each row of column AD on 'Sheet1' for value = "No" and
> search all fields on 'Sheet2' for the value in Column B of same row.
> The colored cell on 'Sheet2' will always in the the same column but 1
> row up.
>
> Thank you for any assistance you can provide.
>
> Dwayne P.



 
Reply With Quote
 
DPelletier
Guest
Posts: n/a
 
      5th Nov 2009
On Nov 5, 5:16*pm, "JLGWhiz" <JLGW...@cfl.rr.com> wrote:
> If I understood the parameters correctly, this should work. *You can rename
> the sheets to suit in the Set statements.
>
> Sub colorNo()
> * *Dim sh1 As Worksheet, sh2 As Worksheet, fStr As Variant
> * *Dim lr1 As Long, rng As Range, fRng As Range
> * *Set sh1 = Sheets("Sheet1")
> * *Set sh2 = Sheets("Sheet2")
> * *lr1 = sh1.Cells(Rows.Count, "AD").End(xlUp).Row
>
> * *Set rng = sh1.Range("AD2:AD" & lr1)
> * * * For Each c In rng
> * * * * *If c.Value = "No" Then
> * * * * * *fStr = sh1.Range("B" & c.Row).Value
> * * * * * *With sh2
> * * * * * *Set fRng = .UsedRange.Find(fStr, LookIn:=xlValues,
> LookAt:=xlWhole)
> * * * * * * * If Not fRng Is Nothing Then
> * * * * * * * * *fAddr = fRng.Address
> * * * * * * * * * * Do
> * * * * * * * * * * * * fRng.Offset(-1).Interior.ColorIndex = 3
>
> * * * * * * * * * * * * Set fRng = .UsedRange.FindNext(fRng)
>
> * * * * * * * * * * Loop While Not fRng Is Nothing And fRng.Address <> fAddr
> * * * * * * * *End If
> * * * * * * * *End With
> * * * * * End If
> * * * *Next
> End Sub
>
> "DPelletier" <sk8rdude...@yahoo.com> wrote in message
>
> news:5f3ab4f9-0587-45a9-b2c2-(E-Mail Removed)...
>
> >I need help cell coloring based upon matching data on 2 sheets.

>
> > 'Sheet1' - Data Dump
> > 'Sheet2' - New Formatting

>
> > 'Sheet1' column AD = "No" then find value on same row but in Column B
> > Then search on 'Sheet2' for that value in Column B. *If found, color
> > the field in the row above it Red (Color.Index = 3)

>
> > I need to check each row of column AD on 'Sheet1' for value = "No" and
> > search all fields on 'Sheet2' *for the value in Column B of same row.
> > The colored cell on 'Sheet2' will always in the the same column but 1
> > row up.

>
> > Thank you for any assistance you can provide.

>
> > Dwayne P.


Works like a charm. Thank you for your time. I could not get the
find value to work before.
 
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 name of worksheet based on data in cell of another worksheet bss5974@yahoo.com Microsoft Excel Programming 14 21st Apr 2011 10:04 PM
Changing Cell Background Color based on data from another cell Speedy Microsoft Excel Misc 2 16th Mar 2009 04:10 PM
Re: Changing cell text color based on cell number W. Wheeler Microsoft Excel Programming 1 23rd Apr 2007 07:24 AM
Re: Changing cell text color based on cell number W. Wheeler Microsoft Excel Programming 0 22nd Apr 2007 11:56 PM
Changing cell text color based on cell number =?Utf-8?B?c2NvdHR5?= Microsoft Excel Programming 9 14th Apr 2007 06:34 AM


Features
 

Advertising
 

Newsgroups
 


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