0
我正在尋找代碼語法來設置單元格顏色填充不透明度(更亮或更暗),具體取決於是否滿足條件。以下代碼將轉到最後一行數據,並朝向第一行。有條件地格式化單元格屬性 - 填充顏色和不透明度
它專注於價格欄,如果當前價格高於前一價格,則設置顏色(黑色),如果當前價格低於之前價格,則設置另一種顏色(紅色)。
另外,如何指定不是顏色常量的顏色?
代碼片段:
'Loop through a recordset from the bottom up and determine
'if current row cell value is greater than the previous one
'recordset sort is descending date (most current date at top)
'go to oldest date and work up until most current date
Public Sub testing()
Dim ws As Worksheet
Dim endRow As Integer
Dim i As Integer
Dim thisRow As Integer
Dim nextRow As Integer
Dim pastRow As Integer
Set ws = ThisWorkbook.Worksheets("DataSheet")
endRow = ws.Range("A" & Rows.Count).End(xlUp).Row 'go to last row and work up
i = endRow
While i >= 1
'Working up the sheet doing whatever
thisRow = i 'the current row or date under consideration
nextRow = i - 1 'the row above (next day) - working up
pastRow = i + 1 'the row below (previous day)
If pastRow < endRow Then 'skip the last row of data, start at 2nd to last
If nextRow > 0 Then 'as long as there is a tomorrow lets work with today
'If current day´s value is greater than previous day,
'color current day cell (black), else color (Blue)
If Cells(i, 2).Value > Cells(pastRow, 2).Value Then
Range(Cells(i, 8), Cells(i, 8)).Interior.Color _
= ColorConstants.vbBlack
'looking for code to set color intensity (lighter or darker)
'also how to define a color other than a color constant
Else
Range(Cells(i, 8), Cells(i, 8)).Interior.Color _
= ColorConstants.vbRed
End If
End If
End If
i = i - 1
Wend
End Sub
乾杯!
感謝您的幫助,但我需要一個Excel Mac VBA解決方案。 – phreshsprout