如果缺陷状态准备好重新testing,使用VBAmacros分割并着色重复的行值

在这里输入图像说明 基于评论的改写。

1.如果F栏中的状态=准备重新testing或通过

2.如果列C中有任何值,则用逗号(,)分隔C列中的重复ID

3.在列A中查找重复的ID并用绿色标记

恩。 在行1中,缺陷ID JIRA1有两个重复的ID ALM3和ALM7。 所以我需要在列A中查找这些值。4.如果这些缺陷(ALM3和ALM7)的状态没有closures,那么我需要用绿色标记整行

Sub findduplicateColoreIt()

'Get the last row Dim Report As Worksheet Dim i As Integer, j As Integer Dim lastRow As Integer Set Report = Excel.Worksheets("Sheet2") lastRow = Report.UsedRange.Rows.Count Application.ScreenUpdating = False For i = 2 To lastRow For j = 2 To lastRow If Report.Cells(i, 4).Value <> "" And Report.Cells(i, 7).Value = "Ready to retest" And Report.Cells(i, 1).Value = "Jira" Then 'This will omit blank cells at the end (in the event that the column lengths are not equal. If InStr(1, Report.Cells(j, 2).Value, Report.Cells(i, 3).Value, vbTextCompare) > 0 Then ' need to get a logic where i need to get value from Colum D, split it and find the value in column A and color the row with green/any. a = Split(ActiveCell.Value, ",") Exit For Else End If End If Next j Next i 

我正在解释你的评论意思是:

  1. 列I包含有关当前状态的信息。 它会有一些关键词,如“closures”,“新build”,“封锁”,“打开”。 现在,你有一个新的关键词“通过”(我猜测)。
  2. 每个关键字都有相应的颜色,用于突出显示同一行中的某些单元格。 在新的关键字“通过”的情况下,你想要的颜色是绿色的。

我正在解释你的问题是: 如何修改我已经有的代码,当我find关键词“Passed”时,使单元格颜色为绿色?

您的代码修改为解决问题,如下所示。

 Private Sub Worksheet_Activate() Dim rng As Range, cell As Range Set rng = Range("I2:I250") For Each cell In rng Select Case cell.Offset(0, 0).Value Case "Closed" cell.Resize(1, 12).Interior.ColorIndex = 4 Case "New" cell.Resize(1, 12).Interior.ColorIndex = 31 Case "blocked" cell.Resize(1, 1).Interior.ColorIndex = 50 Case "open" cell.Resize(1, 1).Interior.ColorIndex = 27 Case "Passed" cell.Resize(1, 1).Interior.ColorIndex = 4 Case Else cell.Resize(1, 1).Interior.ColorIndex = 3 End Select Next ' if the "Winner" Defect passed retest, now "Loser" can retest which should be green in color , i havee multiple Losed defect id associated to one id separated with (,), so if Winner is passed i need to make all loser to green color End Sub 

我select数字4代表绿色根据MSlogging的默认调色板。 由于您已经使用数字4作为“已closures”,因此您可能已经使用绿色突出显示,或者您可能正在使用自定义调色板。