1
我有兩個工作在兩列的VBA代碼:列A和列B.基本上,它在列B上循環,並嘗試在列A中查找每列B值。 ,列A中的某些值具有藍色的單元(內部)顏色。VBA宏沒有正確檢測內部或字體顏色
所以可以有3分的結果:
- 如果在列A中沒有找到一個列B值,則該列B值具有其小區(室內)顏色設置爲紅色。
- 如果在列A中找到列B值,並且列A中的值具有藍色單元格(內部)顏色,則該列B值將其單元格(內部)顏色設置爲黃色。
- 如果在列A中找到列B值,並且列A中的值不具有藍色單元格(內部)顏色,則該列B值將其單元格(內部)顏色設置爲綠色。
點1可以工作,但是對於分離點2和3的IF檢查不起作用。所有這些情況都會自動轉到第3點。
有人可以確定問題嗎?
代碼:
Sub Looper()
Dim i As Integer
Dim Sel As String
Dim MoveDown As String
Dim sourceVal As String
Dim Program As String
Dim i2 As Integer
Dim MoveDown2 As String
Dim Sel2 As String
Dim destVal As String
Dim found As Boolean
i = 2
MoveDown = "YES"
MoveDown2 = "YES"
i2 = 2
Do Until MoveDown = "DONE"
Sel = "B" + Replace(Str(i), " ", "")
sourceVal = Range(Sel).Value
If Range(Sel).Value = "" Then
MoveDown = "DONE"
Else
MoveDown2 = "YES"
i2 = 2
found = False
Do Until MoveDown2 = "DONE"
Sel2 = "A" + Replace(Str(i2), " ", "")
destVal = Range(Sel2).Value
If Range(Sel2).Value = "" Then
MoveDown2 = "DONE"
Else
If destVal = sourceVal Then
If Range(Sel2).Interior.Color = vbBlue Then
Range(Sel).Interior.Color = vbYellow
Else
Range(Sel).Interior.Color = vbGreen
End If
found = True
End If
End If
i2 = i2 + 1
Loop
If found = False Then
Range(Sel).Interior.Color = vbRed
End If
End If
i = i + 1
Loop
End Sub
檢查該被細胞人工藍色或者它是條件格式化的結果? – JosieP