我需要编写一个宏:我用黑色填充 A1。然后当我运行宏时,A2 应该更轻一点,A3 更轻......等等,直到 A20 是白色的。“F5”单元格值应控制梯度指数的程度。当前代码按比例更改颜色。当我更改“F5”中的值(例如从 1 到 0.7)时,所发生的情况是这 20 个单元格(“A1:A20”)中的所有单元格都变暗了。最后一个单元格 A20 不再是白色的了。
但是,无论如何,我都需要我的第一个单元格“A1”为黑色,最后一个单元格“A20”为白色......而且,单元格的颜色分布应该是指数的,即 A1 和 A2 之间的暗度差异应该是 A3 和 A2 之间的暗度差异的两倍(如果“F5”==2),等等......
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 Double 'double precision factor for changing the contrast 0= none higher is more
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 -1)
Next
我不知道,我应该在上面实现什么函数,以便颜色的变化是指数的,因为我改变了contrast
“F5”中变量的值?// 和
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("F5")) Is Nothing Then
Call Macro3
End If
End Sub