我正在寻找代码语法,根据满足或不满足条件,设置单元格颜色填充不透明度(更亮或更暗)。以下代码转到最后一行数据并向上朝向第一行。
如果当前价格高于先前价格,则关注价格列并设置颜色(黑色),如果当前价格低于先前价格,则设置另一种颜色(红色)。
另外,如何指定不是颜色常数的颜色?
代码段:
'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
干杯!!
答案 0 :(得分:0)
我没有Mac,所以无法发出真实的答案,但如果你遇到困难,我只是想试着帮助我做你想做的事情:
希望这有帮助,
TEPP