我正在尝试做一个宏,它将系统地比较单元格值。我有 2 个数据集。我打算创建的宏基本上会将“C3:M25”的值与“O3:Y25”的值进行比较。
我的宏应该开始将范围(“C3”)中的值与范围(“O3”)进行比较。如果 C3.value > O3.value,它将改变 internal.colourindex.value 和字体颜色
完成第一次比较后,它将向下移动到下一行,即比较 range("C4").value 和 range("O4")。该过程继续进行,直到它到达列中的第一个空白行,在本例中为 Range("C26")。
一旦 range("C26") 是一个空单元格,那么宏将重复比较过程,但这一次它将基本上将 Range("D3") 中的值与 Range("P3") 进行比较。循环继续进行,直到整个过程完成。
Sub ilovetocompare()
Dim ross As Long, colss As Long
Dim wb As Workbook, ws1 As Long, ws1row As Integer
Set wb = ActiveWorkbook.Sheets("Pricer")
wb.Range("C3").Activate
With ActiveCell
ws1row = Worksheets("pricer").Range("B3").End(xlDown).Rows.Count
'get the last row count
'macro will stop when it detects that the cells is filled with other colors
Do Until ActiveCell.Interior.Color = 255
'start comparing the prices
For ross = 3 To ws1row
For colss = 15 To 25 ' number of columns will remain unchanged
If ActiveCell.Value > Cells(ross, colss).Value Then
ActiveCell.Font.Bold = True
ActiveCell.Font.colour = vbWhite
'once done with comparison, jump to the next row
ActiveCell.Offset(1, 0).Activate
'the column O likewise also move 1 row down for comparison
Next ross
'when the it hits an empty row, the activecell got readjusted back to the top
ElseIf ActiveCell.Value = "" Then
ActiveCell.Offset(-ws1row, 1).Select
With Selection
Loop
'move the cell up again so that i can resume the comparsion
'create this into a loop
End Sub