我試圖有條件格式化基於在列到每個單體電池組羣左邊的數字的單元格區域。基本上,如果在第13行中,每個單元格組左邊的灰色列= 0,那麼我希望整個單元格組右移綠色,如果= 15,則變爲黃色,如果= 25變爲紅色。第12行是我現在的代碼正在發生的事情,第13行是我想要的樣子。我似乎無法得到正確的循環。
Sub Highlight3()
For i = 1 To ActiveSheet.Cells(Rows.Count, 4).End(xlUp).Row
If Cells(i, 4) = "Highlight" Then
For j = 1 To 15
Range(Cells(i, j * 4 + 2), Cells(i + 1, j * 4 + 4)).Select
Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$E$23 = 0"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.Color = rgbRed
End With
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$E$23= 15"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.Color = rgbGold
End With
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$E$23 = 25"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.Color = rgbGreen
End With
Next j
End If
Next i
End Sub
您的公式將鏈接鎖定到單元格E23。嘗試刪除'$'標誌,看看會發生什麼。 –
這有幫助,但格式本身仍然無法正常工作,雖然 – durba138