PDA

View Full Version : [SOLVED:] Match Criteria on two Sheets and see if the Conditions are met



trevor2524
09-03-2014, 08:59 AM
Hello, I'm trying to do a big macro and have a step for it that I was trying to break down in pieces.

Step 1: Check Column C in Sheet1 for color values in the cell. If it has a color value in a cell take the actual value and see if it exists in Column A on Sheet2.(I have a similar macro included in the example that does this but its looking for ones that don't exist on sheet 2 and adds them to it)

Step 2: When the value is found it will check Column I for a value of "Yes"

Step 3: If no value is found then it will check to see if the date in Column D matches the date in Column F on sheet1. If it does then on Sheet2 Column H will receive the Value of "Yes"

If these conditions are not met it will then move onto the next color value cell on sheet1. This is part of a bigger macro so I'm trying to break it down.

12219

Thanks for the help.

Tinbendr
09-03-2014, 11:15 AM
See if this gets you close.

Sub CheckForColor()
Dim WS1 As Worksheet
Dim WS2 As Worksheet
Dim C As Range
Dim LastRow As Long
Dim WkRg As Range
Dim F As Range

Set WS1 = Sheets("Sheet1")
With WS1
Set WkRg = .Range("C1:C" & .Range("C" & Rows.Count).End(xlUp).Row)
End With
For Each F In WkRg
If F.Interior.ColorIndex <> xlColorIndexNone Then
Debug.Print F.Interior.ColorIndex
Set WS2 = Sheets("Sheet2")
With WS2
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

With .Range("A8:A" & LastRow)
Set C = .Find(F.Value, LookIn:=xlValues)
If Not C Is Nothing Then
If UCase(WS2.Range("I" & C.Row)) = "YES" Then
WS2.Range("H" & C.Row) = "Yes"
Else
If WS2.Range("D" & C.Row) = WS1.Range("F" & F.Row) Then
WS2.Range("H" & C.Row) = "Yes"
End If
End If
End If
End With
End With
End If
Next F
End Sub

trevor2524
09-03-2014, 12:55 PM
Thank You.