cell color change by another cell value if there is even one "daleyed"

negarshaban

New Member
Joined
Dec 29, 2018
Messages
18
i have a calender in sheet6 and database is sheet1

there is one mistake,

i want if there is even one "delayed" on sheet1.column "i" , change cell color (matched data) in sheet6 to red

and if all was "completed",cell color change to green

and if there is no delayed and all is not completed

,cell color change to yellow





and when change month and year from dropdowns, if it doesn't have any task, return the background-color

VBA Code:
Private Sub Worksheet_Activate()
 
    Dim sh As Worksheet, wInt As Variant
    Dim j As Long
    Dim row1 As Integer
    Dim cl1 As Integer
    Set sh = Sheet3
    For row1 = 5 To 15
    For cl1 = 2 To 8
    wInt = Cells(row1, cl1).Value
    
    For j = 2 To sh.Range("c" & Rows.Count).End(xlUp).Row
      If sh.Range("c" & j).Value = wInt Then
         If sh.Range("i" & j).Value = "Completed" Then
       Cells(row1, cl1).Offset(1, 0).Interior.Color = vbGreen
            Else
              Cells(row1, cl1).Offset(1, 0).Interior.Color = vbYellow
               End If
             End If
    Next
    Next
    Next
  

End Sub
 

Attachments

  • ask1.JPG
    ask1.JPG
    57 KB · Views: 7
  • ask 2.JPG
    ask 2.JPG
    51.9 KB · Views: 7

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
I don't understand when it should change to yellow. Maybe if you explain to me with a couple of examples and I adjust it in the code.
Try the following:


VBA Code:
Private Sub Worksheet_Activate()
  Dim sh As Worksheet, wInt As Variant, r As Range
  Dim row1 As Integer, cl1 As Integer
  Dim wCount1 As Long, wCount2 As Long, wCount3 As Long
  
  Set sh = Sheet3
  Set r = sh.Range("C2:C" & sh.Range("C" & Rows.Count).End(xlUp).Row)
  
  For row1 = 5 To 15 Step 2
    For cl1 = 2 To 8
      wInt = Cells(row1, cl1).Value
      Cells(row1, cl1).Offset(1, 0).Interior.Color = xlNone
      wCount1 = WorksheetFunction.CountIf(r, wInt)
      wCount2 = WorksheetFunction.CountIfs(r, wInt, r.Offset(, 6), "Completed")
      wCount3 = WorksheetFunction.CountIfs(r, wInt, r.Offset(, 6), "Delayed")
      Select Case True
        Case wCount1 = 0
        Case wCount1 = wCount2  'all was "completed"
          Cells(row1, cl1).Offset(1, 0).Interior.Color = vbGreen
        Case wCount1 = wCount3  'cell color change to yellow
          Cells(row1, cl1).Offset(1, 0).Interior.Color = vbYellow
        Case Else               'is even one "delayed"
          Cells(row1, cl1).Offset(1, 0).Interior.Color = vbRed
      End Select
    Next
  Next
End Sub
 
Upvote 0
yeeeeeeeeeeeeeeeeeee
I don't understand when it should change to yellow. Maybe if you explain to me with a couple of examples and I adjust it in the code.
Try the following:


VBA Code:
Private Sub Worksheet_Activate()
  Dim sh As Worksheet, wInt As Variant, r As Range
  Dim row1 As Integer, cl1 As Integer
  Dim wCount1 As Long, wCount2 As Long, wCount3 As Long
 
  Set sh = Sheet3
  Set r = sh.Range("C2:C" & sh.Range("C" & Rows.Count).End(xlUp).Row)
 
  For row1 = 5 To 15 Step 2
    For cl1 = 2 To 8
      wInt = Cells(row1, cl1).Value
      Cells(row1, cl1).Offset(1, 0).Interior.Color = xlNone
      wCount1 = WorksheetFunction.CountIf(r, wInt)
      wCount2 = WorksheetFunction.CountIfs(r, wInt, r.Offset(, 6), "Completed")
      wCount3 = WorksheetFunction.CountIfs(r, wInt, r.Offset(, 6), "Delayed")
      Select Case True
        Case wCount1 = 0
        Case wCount1 = wCount2  'all was "completed"
          Cells(row1, cl1).Offset(1, 0).Interior.Color = vbGreen
        Case wCount1 = wCount3  'cell color change to yellow
          Cells(row1, cl1).Offset(1, 0).Interior.Color = vbYellow
        Case Else               'is even one "delayed"
          Cells(row1, cl1).Offset(1, 0).Interior.Color = vbRed
      End Select
    Next
  Next
End Sub
yeeeeeeeeeeeeees.
it's worked.
you are so professional.

:love::love::love::love:(y)
 
Upvote 0
I'm glad to help you. I appreciate your kind comments.
 
Upvote 0

Forum statistics

Threads
1,215,111
Messages
6,123,159
Members
449,098
Latest member
Doanvanhieu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top