2016-04-25 45 views
0

我已在bolow要求,其中我已经取得了一些颜色的重复值,但我仍然需要一些帮助从一系列列的拆分值,并使用VB宏

  1. 如果G中列中的状态=就绪重新测试或通过
  2. 然后,如果有在列C的任何值,采取/拆分重复ID列C与逗号(,)隔开
  3. 搜索在列A的重复的ID以及与绿色色彩
  4. 其标记

[![示例数据] [1]] [1]

ex。在第1行中,缺陷ID CMS-921有两个重复的id 44和163693.所以我需要在列A中查找这些值。

  1. 如果这些缺陷的状态(44和163693)不然后关闭我需要标记整个行中的绿颜色的我当前的代码

实施例:

Sub findduplicateColorIt() 
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, ",") 
      For Text = 0 To UBound(a) 
      MsgBox a(Text) 
      Next Text 

      Exit For 
     Else 
     End If 
    End If 
Next j 
Next i 

Application.ScreenUpdating = True 

End Sub 
+0

你究竟在做什么问题? (发现重复项,分割值,for循环不起作用等) –

+0

看起来你有一个“Else”,它没有做任何事情。 –

+0

@CodyG。现在数组a = Split(ActiveCell.Value,“,”)具有多个值,现在我需要从(i)中取个别值并在列B中搜索并为整行着色..我无法获得逻辑为... – Venkat

回答

0

Venkat ...以此作为逻辑的示例。我相信你需要添加一些东西来避免/捕获错误。

Sub findduplicateColorIt() 
Dim Report As Worksheet 
Dim a() As String 
Dim i As Long, j As Long 
Dim lastRow As Long, chkRow As Long 

Set Report = Excel.Worksheets("Sheet3") 
lastRow = Report.UsedRange.Rows.Count 

Application.ScreenUpdating = False 
For i = 2 To lastRow 
    If Report.Cells(i, 4).Value <> "" And _ 
     (InStr(Report.Cells(i, 7).Value, "Ready to retest") > 0 Or _ 
     InStr(Report.Cells(i, 7).Value, "Passed") > 0) And _ 
     InStr(Report.Cells(i, 1).Value, "JIRA") > 0 Then 'This will omit blank cells at the end (in the event that the column lengths are not equal. 

     a = Split(Report.Cells(i, 3).Value, ",") 
     For j = 0 To UBound(a) 
      chkRow = Report.Range("B1:B" & lastRow).Find(a(j)).Row 
      If chkRow > 0 Then 
       If Not InStr(Report.Cells(chkRow, 7).Value, "Closed") > 0 Then 
        Debug.Print Report.Range("A" & i).Address 
        Report.Range("A" & i).EntireRow.Interior.Color = vbGreen 
       End If 
      End If 
     Next j 
    End If 
Next i 

Application.ScreenUpdating = True 

End Sub 
+0

感谢代码工作,因为我想,只是改变了几件事 chkRow = Report.Range(“B1:B”&lastRow).Find(a(j))。行 Debug.Print Report.Range (“B”和chkRow)。地址 如果chkRow> 0 Then If Not InStr(Report.Cells(chkRow,7).Value,“Closed”)> 0 Then Debug.Print Report.Range(“A” a(j))。Address 'Report.Range(“A”&i).EntireRow.Interior.Color = vbGreen Report.Range(“A”&chkRow).EntireRow.Interior.Color = vbGreen End If 万一 – Venkat