我对宏很新。只需要在工作中完成这项小任务。 概述:我正在运行两个不同的配方/程序来生成数据。
每个备用行都是从不同配方生成的读数。我想比较同一张表中的最后两行。如果值的标准偏差大于0.5,我需要报告或更改单元格的颜色。我该怎么做?
我写了以下内容,但它对我不起作用:
Sub checkit()
Row1length = Worksheets("Sheet1").Cells(1, Columns.Count).End(xlToLeft).Column
For i = 1 To Row1length
If Worksheets("Sheet1").Cells(7, i).Value <> Worksheets("Sheet1").Cells(8, i) Then
Match = False
Exit For
End If
Next
If Match = True Then
Debug.Print "match"
Else
Debug.Print "not match"
End If
End Sub
答案 0 :(得分:0)
此代码将遍历工作表中的所有行,并将第一行与第二行进行比较,标记具有不同值的单元格。
Sub CheckIt()
Const FirstDataRow As Long = 2 ' change as required
Dim Rl As Long, Cl As Long
Dim R As Long, C As Long
With Worksheets("Sheet1") ' change the sheet name
Rl = .Cells(.Rows.Count, "A").End(xlUp).Row
Cl = .Cells(FirstDataRow, .Columns.Count).End(xlToLeft).Column
For R = FirstDataRow To Rl Step 2
For C = 1 To Cl
If (.Cells(R, C).Value) <> (Cells(R + 1, C).Value) Then
Range(.Cells(R, C), Cells(R + 1, C)).Interior.Color = vbYellow
End If
Next C
Next R
End With
End Sub