我需要寫一個宏,以便:我用黑色填充A1。然後當我運行宏時,A2應該稍微輕一些,A3甚至更輕......等到A20變白。 「F5」單元值應該控制梯度指數的程度。 當前代碼按比例改變顏色。當我改變「F5」的值(例如從1到0.7)時,發生的是所有這20個單元(「A1:A20」)變得等於較暗。而最後一個單元格A20不再是白色。如何強制excel單元更改顏色EXPONENTIALLY?
然而,我需要我的拳頭細胞「A1」爲黑色,最後一個細胞「A20」爲白色無論如何...而且,細胞的顏色分佈應該是指數,即A1和A2之間暗之間的差別應該是兩次(如果「F5」 == 2)大到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 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中提供精確值(如所示)或類似的東西? – 2013-04-29 05:21:13
@KazJaw我只需要類似。我只是試圖展示一個能夠描述我需要的例子。 – Buras 2013-04-29 05:58:03