excel VBA如何设置单元颜色为默认的颜色(自动的黑色)

20 To 89 Step 3(T列到CK列)
给代码加表名(因安键在别表)
以T最后显示为起点,到第10(这里我可以修改为哪一行)行结束

你选菜单开始录制宏,设置一个单元格的颜色为自动,停止录制,查看这个宏的代码:

Sub 宏1()
'
' 宏1 宏
'

'
    With Selection.Font
        .ColorIndex = xlAutomatic
        .TintAndShade = 0
    End With
End Sub

现在你就明白了,设置单元格颜色为自动的语句应该是:

Selection.Font.ColorIndex = xlAutomatic


在你的代码里面可以这样写:

for i=20 to 89 step 3
    for j=4 to 10
        cells(i,j).Font.ColorIndex = xlAutomatic
    next j
next i追问

With Sheet2用这样的表名?

Sub 宏1()

With Sheet2.Select

for i=20 to 89 step 3

for j=4 to 10

cells(i,j).Font.ColorIndex = xlAutomatic

next j

next i

End With

End Sub

追答

你这个with是什么意思?

我的语句:
cells(i,j).Font.ColorIndex = xlAutomatic

表示修改代码运行时会显示的这个表,如果需要指定sheet2代码应该这样:
sheet2.cells(i,j).Font.ColorIndex = xlAutomatic

追问

Sub 宏1()
For i = 20 To 89 Step 3
For j = 1483 To 2000
Sheet2.Cells(i, j).Font.ColorIndex = xlAutomatic
Next j
Next i
End Sub
是这样吗?
Sheet2.Cells(i, j).Font.ColorIndex = xlAutomatic这句提示

追答

提示的什么?

我粘贴了你的语句,在我的电脑上执行没有任何错误,完全正确。我第一次给你的代码没有Sheet2,你自己偏要加上的,如果你只有一个工作表,那么肯定会错,因为第一个工作表的名称应该是Sheet1。

追问

我工作表有多个,所以Sheet2不错,

cells(i,j).Font.ColorIndex = xlAutomatic用这个也是一样的提示

追答

你的i,j弄反了,没有2000列,cells出界。

追问

For j = 1483 To 2000这个不 是行的范围?哪行是如何控制它的范围
还有就是,我的单元格里的内容为其它颜色,哪为什么还是原来的原色,没有被修改为默认的颜色(自动的黑色)呢?

追答

cells(行,列),行的范围1~65536,列的范围1~256

温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2016-01-26
可以用如下代码实现:
sub main
for i=20 to 89 step 3
for j=4 to 10
cells(i,j).interior.ColorIndex = xlAutomatic
next j
next i
end sub

关于此例中用到的interior对象:
对象代表指定对象的内部,为只读属性
第2个回答  2015-12-05
Sub s()
    Selection.Font.ColorIndex = xlAutomatic
End Sub

相似回答