excel vbA给固定内容的单元格填充颜色

1.用VBA
2.。区域为B10:Z15
3。单元格内容为AA填充单元格为红色
4.。单元格内容为QQ填充单元格为黄色
5.。单元格内容为QP填充单元格为青色

sub xx()
for each c in [b10:z15]
    if c="AA" then
        c.interior.color=vbred
     elseif c="QQ" then
         c.interior.color=vbyellow
      elseif c="QP"
          c.interior.color=vbcyan
      endif
 next
 end sub
温馨提示:答案为网友推荐,仅供参考
第1个回答  2015-06-02
必须用VBA吗?条件格式更加容易设置。追问

对,用VBA

追答

Sub 填色()

Set quyu = Application.InputBox("请选择单元格地址然后确定", "", "range", , , , , 8)

For Each cel In quyu

    If cel = "QQ" Then cel.Interior.ColorIndex = 6

    If cel = "QP" Then cel.Interior.ColorIndex = 8

    If cel = "AA" Then cel.Interior.ColorIndex = 3

Next

End Sub


放大图片查看操作。


使用inputbox可以很方便的控制单元格区域,等同于selection。

相似回答