Excel 2010 VBA:设置上一列中单元格引用单元格的颜色
我有一个填充工作表并将值复制到网格中的宏。我想向单元格添加条件格式,这样当它们更新时,如果它们变得大于前一列,它们就会变成红色,变小,它们就会变成绿色,变成 0,它们就会变成灰色。
我的问题是添加条件并引用单元格。
Set newCell = originalEstimateCell.Offset(0, 2 + i)
newCell.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreater, Formula1:="XX"
newCell.FormatConditions(1).Interior.Color = RGB(255, 0, 0)
我的问题是用什么替换 XX 来引用同一行中的前一列,即。如果我们在 C7 单元格,我想参考 B7 单元格。
谢谢
I have macro that populates a sheet, and copies values into a grid. I want to add conditional formatting to the cells, so that when they are updated if they become greater than the previous column they turn red, smaller they turn green and become 0 they turn grey.
My problem is adding the condition and referenceing the cell.
Set newCell = originalEstimateCell.Offset(0, 2 + i)
newCell.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreater, Formula1:="XX"
newCell.FormatConditions(1).Interior.Color = RGB(255, 0, 0)
My question is what replaces the XX to refer to the previous column in the same row, ie. if we are in Cell C7 I want to refer to cell B7.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个
上面的代码指出当前单元格的值应该大于 Formula1 的值,并且公式本身是活动单元格前一列的单元格的地址。如果您希望相对于活动单元格设置其他单元格的格式,只需更改偏移方法的参数即可。
我希望它有帮助。
Try this one
The code above states that the current cell value should be greater than the value of the Formula1, and the formula itself is the address of the cell one column before the active cell. If you want some other cell to be formatted, relatively to the active cell, just change the paramters of the offset method.
I hope it helped.
C6 将是 C7 的上一个行,而不是上一列
尝试
从上一行获取值
C6 would be the previous row to C7, not the previous column
Try
to get the value from the previous row