我已经在Excel中设置了一个VBA程序,当给定行中的几个单元格的条件彼此相等时,它将突出显示一个单元格。(请参见下面的代码)调试器上没有出现错误,并且指定的单元格没有突出显示。
在下面的示例数据中,该程序将在情况1的行中突出显示一个单元格(1 = 1)和(10 = 10)。关于如何工作的任何建议?
Sub x()
Dim r As Integer
Dim c As Integer
With Worksheets(1)
For r = 1 To .Range("B" & Rows.Count).End(xlUp).row
c = .Cells(r, Columns.Count).End(xlToLeft).Column
If Cells(r, 3).Value = Cells(r, 6).Value & Cells(r, 4).Value = Cells(r, 7).Value Then
Cells(r, 13).Interior.ColorIndex = 46
Application.ScreenUpdating = True
End If
Next r
End With
End Sub
样本数据:
Case_1 HT 1 10 STD 1 10 0.008893 0.02564 71 0.35 0.7297
Case_2 HT 1 10 HT 1 15 -0.04434 0.02564 71 -1.73 0.0881
Case_3 HT 1 10 STD 1 15 0.008893 0.02564 71 0.35 0.7297
上述所有评论都很好,但我想我会把它们放在一起。
您需要更改"&''到"one_answers"。
消除;"昏暗的C"线," C =单元"线和"应用"。Screenupdating"行。
我正在运行Excel 2010;您的代码与上述更改一起使用,使用" if"语句中的" .cells"或"单元格"。
我还从每个单元引用中删除了"。值",它可以使用或不使用它。
Dim r As Integer
'Dim c As Integer
With Worksheets(1)
For r = 1 To Range("B" & Rows.Count).End(xlUp).Row
'c = Cells(r, Columns.Count).End(xlToLeft).Column
If Cells(r, 3) = Cells(r, 6) And Cells(r, 4) = Cells(r, 7) Then
Cells(r, 13).Interior.ColorIndex = 46
'Application.ScreenUpdating = True
End If
Next r
End With