Tôi đã làm lại câu trả lời của Bartdude, cho ánh sáng Xám/trắng dựa trên một cột cấu hình, sử dụng các giá trị RGB. Một biến boolean được lật khi giá trị thay đổi và điều này được sử dụng để lập chỉ mục mảng màu sắc thông qua các giá trị số nguyên của True và False. Làm việc cho tôi vào năm 2010. Gọi cho phụ với số tờ.
Public Sub HighLightRows(intSheet As Integer)
Dim intRow As Integer: intRow = 2 ' start at 2, cause there's nothing to compare the first row with
Dim intCol As Integer: intCol = 1 ' define the column with changing values
Dim Colr1 As Boolean: Colr1 = True ' Will flip True/False; adding 2 gives 1 or 2
Dim lngColors(2 + True To 2 + False) As Long ' Indexes : 1 and 2
' True = -1, array index 1. False = 0, array index 2.
lngColors(2 + False) = RGB(235, 235, 235) ' lngColors(2) = light grey
lngColors(2 + True) = RGB(255, 255, 255) ' lngColors(1) = white
Do While (Sheets(intSheet).Cells(intRow, 1) <> "")
'check for different value in intCol, flip the boolean if it's different
If (Sheets(intSheet).Cells(intRow, intCol) <> Sheets(intSheet).Cells(intRow - 1, intCol)) Then Colr1 = Not Colr1
Sheets(intSheet).Rows(intRow).Interior.Color = lngColors(2 + Colr1) ' one colour or the other
' Optional : retain borders (these no longer show through when interior colour is changed) by specifically setting them
With Sheets(intSheet).Rows(intRow).Borders
.LineStyle = xlContinuous
.Weight = xlThin
.Color = RGB(220, 220, 220)
End With
intRow = intRow + 1
Loop
End Sub
thưởng Tùy chọn: cho dữ liệu SQL, màu sắc bất kỳ giá trị NULL với cùng vàng như được sử dụng trong SSMS
Public Sub HighLightNULLs(intSheet As Integer)
Dim intRow As Integer: intRow = 2 ' start at 2 to avoid the headings
Dim intCol As Integer
Dim lngColor As Long: lngColor = RGB(255, 255, 225) ' pale yellow
For intRow = intRow To Sheets(intSheet).UsedRange.Rows.Count
For intCol = 1 To Sheets(intSheet).UsedRange.Columns.Count
If Sheets(intSheet).Cells(intRow, intCol) = "NULL" Then Sheets(intSheet).Cells(intRow, intCol).Interior.Color = lngColor
Next intCol
Next intRow
End Sub
Nguồn
2015-06-17 15:21:35
Tôi có thể đã hiểu sai, nhưng từ nơi tôi nhìn thấy nó và từ các thử nghiệm của tôi, thiết bị chuyển mạch này từ màu này sang hàng khác, miễn là cột A và B không trống ... không trả lời câu hỏi. Nhưng tôi có thể đã bỏ lỡ điều gì đó ... –