根据excel VBA中的条件突出显示值

时间:2018-05-07 17:06:41

标签: vba macos excel-vba excel

我是VBA的新手,需要一些帮助。 在我的Excel中,如果状态为“正在进行”,我想突出显示一列。 首先,我必须用逗号分割Col B然后如果状态为正在进行中我想突出显示重复值。

 S.no.     Task          Status  
1.         abc         In progress  
2.         abc,efg     Not Started 



S.no.     Task          Task2          Status  
1.         abc                   In progress  
2.         **abc**      efg     Not Started 



    range for checking duplicates should be both Task and Task 2

    Now this is my code. Any help will be appreciated. 

Sub GetAlert()

    Dim sht1 As Worksheet
    Dim AssociatedVal As String
    Dim AssociatedArr() As String
    Dim Arr As Variant
    Dim matchFoundIndex As Long
    Dim iCntr As Long
    Dim lcol As Long
    Dim data As Range


    Set sht1 = ThisWorkbook.Sheets(1)
    tRows = sht1.Cells(Rows.Count, 1).End(xlUp).Row
    lcol = sht1.Cells(1, Columns.Count).End(xlToLeft).Column

    For Row = 2 To tRows

    AssociatedVal = sht1.Cells(Row, 3).Value


    AssociatedArr() = Split(AssociatedVal, ",")
     Arr = UBound(AssociatedArr) - LBound(AssociatedArr)
    For i = 0 To Arr
        sht1.Cells(Row, lcol + (i + 1)).Value = AssociatedArr(i)
    Next
       For iCntr = 2 To tRows
        If Cells(iCntr, 7) <> "" Then
            'Sheets("Sheet1").Range("$G$1:$H$" & tRows).FindDuplicates Columns:=Array(1, 2), Header:=xlYes
                matchFoundIndex = WorksheetFunction.Match(Cells(iCntr, 7), Range("G1:G" & tRows), 0)
                'If Application.CountIf(Range("G:G"), Target) > 1 Then
                If iCntr <> matchFoundIndex Then
                Cells(iCntr, 11) = "Duplicate"
           End If

            End If
            If Cells(iCntr, 4).Value = "In Progress" And Cells(iCntr, 11).Value = "Duplicate" Then
            Cells(iCntr, 3).Interior.ColorIndex = 3
            End If
    Next
    'Next Arr
    Next
    MsgBox "Fetched"
    End Sub

0 个答案:

没有答案
相关问题