我有一个时间表宏,我循环为第一行的每个单元格赋予随机颜色,并在其中命名标题。 然而,有时会随机出现黑色,这没有用,因为内容也是黑色的。 如何避免黑色(并且可能接近黑色,内容不可见) 以下是我当前代码的一部分(我没有放置整个 for 循环,因为它与此处无关,但此代码基本上循环第一行的每个单元格):
With ActiveSheet
rg.Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = True
.Font.Size = 18
.ColumnWidth = 30
.RowHeight = 80
.Interior.ColorIndex = Int((56 * Rnd) + 1)
End With
End With
你可以做一些事情,比如为你的随机颜色创建一个变量
Dim RandCol As Integer
RandCol = Int((56 * Rnd) + 1)
然后循环直到它不等于1
Do Until RandCol <> 1
RandCol = Int((56 * Rnd) + 1)
Loop
或者再做一次
if RandCol = 1 then
RandCol = Int((56 * Rnd) + 1)
end if
然后用它作为你的颜色索引
.Interior.ColorIndex = RandCol