宏可将两个具有颜色的列进行比较,并获取具有琥珀色的列的数据

时间:2019-06-12 11:32:54

标签: excel vba

我在两列AA和AB列中有一个值列表,并用不同的颜色填充,我的公式应比较AA和AB列,找出哪一列具有琥珀色并在J列中显示该列的值

我试图从AB中提取值并使用excel公式在J列中对其进行更新,但无法构建宏,我试图将AA和AB列与颜色进行比较,并以此为基础提取值。 / p>

=INDEX($1:$1048576,I11,28)

1 个答案:

答案 0 :(得分:0)

您可以尝试:

Option Explicit

Sub test()

    Dim LastRow As Long, i As Long
    Dim strValue As String

    'With statement refer to Sheet1. Change if needed
    With ThisWorkbook.Worksheets("Sheet1")

        'Find Last row of column AA in Sheet1
        LastRow = .Cells(.Rows.Count, "AA").End(xlUp).Row

        'Loop starting from row 1 to LastRow variale. Change Starting position if needed
        For i = 1 To LastRow
            'Check interior color. You may need to change RGB
            If .Range("AA" & i).Interior.Color = RGB(255, 190, 0) Then
                .Range("J" & i).Value = .Range("AA" & i).Value
            Else
                .Range("J" & i).Value = .Range("AB" & i).Value
            End If

        Next i

    End With

End Sub