我需要编写一个宏:我用紫色填充 A1。然后当我运行宏时,A2 应该更轻一点,A3 更轻......等等,直到 A20 是白色的。但是这种颜色变化不应该是成比例的,即“变得更亮”的单元格中的边缘颜色变化应该下降(使得 A2 比 A1 更亮,比 A3 比 A2 更亮)。底线是:细胞应该变得更轻,但不成比例。
到目前为止,我有以下代码:
Sub Macro3()
Dim firstCell As Range 'the first cell, and the cell whose color will be used for all others.
Dim cellColor As Long 'the cell color that you will use, based on firstCell
Dim allCells As Range 'all cells in the column you want to color
Dim c As Long 'cell counter
Dim tintFactor As Double 'computed factor based on # of cells.
Dim contrast As Integer
Set firstCell = Range("A1")
cellColor = firstCell.Interior.Color
contrast = Range("F5").Value
Set allCells = Range("A1:A20")
For c = allCells.Cells.Count To 1 Step -1
allCells(c).Interior.Color = cellColor
allCells(c).Interior.TintAndShade = contrast * _
(c - 1) / allCells.Cells.Count
Next
End Sub
我试图在Dim contrast as Integer
单元格“F5”中引入一个整数变量,这样当我改变“F5”中的值时,颜色的边际减少会下降。但这不起作用。如何改进代码?