![](/img/trans.png)
[英]Conditional Formatting for background color and text based another cell value
[英]Conditional Formatting - Changing cell color based on another cells text
目前正在嘗試調試我的代碼。 我希望該行的第一個單元格根據同一行的單元格中的文本更改特定的顏色。 有條件的文本基於一個下拉列表,用戶可以在宏運行完成后手動輸入該下拉列表。
For polerow = 14 To lastrow + 12
If Cells(polerow, 27).Value = "Simple" Then
Cells(polerow, 1).Interior.ColorIndex = 5
'.Cells(PoleRow,1).Interior.Colorindex = 5
End If
Next
我基本上是想以公式格式編寫內容。 有條件的文本是“簡單”。 謝謝!
我認為您的問題是您尚未設置lastrow
,還需要標識工作簿和工作表引用。
Dim cel As Range, lastrow As Long
lastrow = ThisWorkbook.Sheets("Sheet1").UsedRange.Rows.Count 'sets the number of used rows
'loop through each cell in Col27 from row 14 to the lastrow + 12
For Each cel In ThisWorkbook.Sheets("Sheet1").Range("AA14:AA" & lastrow + 12)
If cel.Value = "Simple" Then 'test cell value for condition
cel.Offset(, -26).Interior.ColorIndex = 5 'if condition is met then offset to first cell in row and color
End If
Next cel 'loop to next cell
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.