当前正在尝试调试我的代码。我希望该行的第一个单元格根据同一行的单元格中的文本更改特定的颜色。有条件的文本基于一个下拉列表,用户可以在宏运行完成后手动输入该下拉列表。
JQuery
我基本上是想以公式格式编写内容。有条件的文本是“简单”。谢谢!
答案 0 :(得分:0)
我认为您的问题是您尚未设置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