ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Color code in 2 column conditional (https://www.excelbanter.com/excel-programming/352117-color-code-2-column-conditional.html)

Charles L. Snyder

Color code in 2 column conditional
 
Hi

I have a spreadsheet similar to this:

RJS JPM CLS CALL BU
VAC MTG CLS
MTG VAC VAC JPM
MTG VAC JPM


My code looks like this:

Sub ck_conflicts()

Dim rng As Range, cell As Range
Dim lastrow As Long
lastrow = Cells(Rows.Count, "K").End(xlUp).Row
Set rng = Range("K4:K" & lastrow)
For Each cell In rng 'offset is 7 columns
If (cell.Value = "RJS" And cell.Offset(0, -7).Value < "") Then
cell.Interior.ColorIndex = 3
MsgBox ("Conflict Found - Color Coded")
Else
MsgBox ("No Conflicts Found")
Exit Sub
End If
Next
End Sub


I am trying to look down each cell in the "Call" column (= K), and
identify where someone's initials are. I then want to look over to the
column where their initials are (same row) and see if the cell is empty
(ie, no conflicts). If there is a conflict, then color the cell. In the
example spreadsheet above, there is a conflict where JPM is listed in
the call column, but also listed as vacation (VAC). I can't see what is
wrong with my code snippet....


Thanks

CLS


Tom Ogilvy

Color code in 2 column conditional
 
Sub ck_conflicts()

Dim rng As Range, cell As Range
Dim lastrow As Long, bConflict as Boolean
lastrow = Cells(Rows.Count, "K").End(xlUp).Row
Set rng = Range("K4:K" & lastrow)
For Each cell In rng 'offset is 7 columns
If (cell.Value = "RJS" And cell.Offset(0, -7).Value < "") Then
cell.Interior.ColorIndex = 3
bConflict = True
End If
Next
if bConflict then
msgbox "One or more conflict was found"
Else
msgbox "No conflicts"
End if
End Sub

--
Regards,
Tom Ogilvy



"Charles L. Snyder" wrote in message
oups.com...
Hi

I have a spreadsheet similar to this:

RJS JPM CLS CALL BU
VAC MTG CLS
MTG VAC VAC JPM
MTG VAC JPM


My code looks like this:

Sub ck_conflicts()

Dim rng As Range, cell As Range
Dim lastrow As Long
lastrow = Cells(Rows.Count, "K").End(xlUp).Row
Set rng = Range("K4:K" & lastrow)
For Each cell In rng 'offset is 7 columns
If (cell.Value = "RJS" And cell.Offset(0, -7).Value < "") Then
cell.Interior.ColorIndex = 3
MsgBox ("Conflict Found - Color Coded")
Else
MsgBox ("No Conflicts Found")
Exit Sub
End If
Next
End Sub


I am trying to look down each cell in the "Call" column (= K), and
identify where someone's initials are. I then want to look over to the
column where their initials are (same row) and see if the cell is empty
(ie, no conflicts). If there is a conflict, then color the cell. In the
example spreadsheet above, there is a conflict where JPM is listed in
the call column, but also listed as vacation (VAC). I can't see what is
wrong with my code snippet....


Thanks

CLS





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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com