【发布时间】:2013-04-22 16:20:09
【问题描述】:
我需要编写一个宏:我用黑色填充 A1。然后当我运行宏时,A2 应该更轻一点,A3 更轻......等等,直到 A20 是白色的。 “F5”单元格值应控制梯度指数的程度。 当前代码按比例更改颜色。当我更改“F5”中的值(例如从 1 到 0.7)时,会发生什么,这 20 个单元格(“A1:A20”)中的所有单元格都变暗了。最后一个单元格 A20 不再是白色的了。
但是,我需要我的第一个单元格“A1”为黑色,最后一个单元格“A20”为白色无论如何......而且,单元格的颜色分布应该是EXPONENTIAL,即 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
我不知道,我应该在上面实现什么功能,以便
颜色的变化将是指数级的,因为我在“F5”中更改了变量contrast 的值?
// 与
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("F5")) Is Nothing Then
Call Macro3
End If
End Sub
【问题讨论】:
-
您是否需要在 B 列中提供准确的值或类似的值?
-
@KazJaw 我只需要类似的。我只是试图展示一个可以描述我需要的示例。