Scripting in Excel — Highlighting like values

笑着哭i 提交于 2019-12-02 04:02:10

This will highlight the second cell in the column. The color might now be the extact color you want though.

EDIT2: added the definition for testcell1, first,Second and Added Report as worksheet code

edit 3: changed <> to =

Sub runthis()


'Dim row As Integer

Dim TestCell As String
Dim first As String
Dim Second As String

Dim TestCell1 As String
Dim lastcell As Integer

Sheets("sheet1").Select

Dim Report As Worksheet
Set Report = Excel.Worksheets("Sheet1")


lastcell = Sheets("sheet1").Cells(Rows.Count, "A").End(xlUp).row

For row = 1 To lastcell
    TestCell = "A" & CInt(row)
    TestCell1 = "A" & (CInt(row) + 1)
    first = Range(TestCell).Value
    Second = Range(TestCell1).Value

    If first = Second Then
        Report.Cells(row, 1).Interior.ColorIndex = 3

    End If
Next row
End Sub
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!