For i = 3 To LastRow CellVal = Cells(i, 2).Value If CellVal = 1 Then Cells(i, 2).Offset(, 1).Value = "特价" Cells(i, 1).Resize(, 2).Interior.Color = RGB(140, 198, 63) End If Next i
然后插入表单控件-按钮;右键编辑名称、指定宏;最后点击运行即可
完整代码示例:
Sub Solution()
Dim LastRow As Long Dim CellVal As Long Dim i As Integer
LastRow = Cells(Rows.Count, 2).End(xlUp).Row
For i = 3 To LastRow CellVal = Cells(i, 2).Value If CellVal = 1 Then Cells(i, 2).Offset(, 1).Value = "特价" Cells(i, 1).Resize(, 2).Interior.Color = RGB(140, 198, 63) End If Next i