2014-10-01 57 views
0

我想使用If statementVBA代碼)來檢查給定數字參數列中的單元格範圍。對於與給定值匹配的單元格,右側(同一行中)的單元格應更改背景顏色。如果聲明檢查Excel列的匹配值

僞代碼示例所示:

A1=5,7 
If cell in Range(F1:F10) has value=A1 Then 
(random matched cell: F7=5,7) 
Range (G7:M7) = Background Blue 

改變,我知道如何做到這一點的背景下,但什麼是檢查給定範圍內的最佳途徑的一部分?

回答

0

我想你想要像

for i = 1 to 10 'rows in column f to loop through 
    if cells(i,6) = cells(1,1) then 'column a is 1, column f is 6, etc. 
    range(cells(i,7), cells(i,13)).interior.colorindex = 'number for that color 
    end if 
next i 
0

我猜你可能在F1中有多行:F10在A1上有匹配。我將通過細胞循環與範圍:

For each rngCell in Range("F1:F10") 
    If rngCell.value = Range("A1").value 
      Range("G" & rngCell.row, "M" & rngCell.row).Interior.ColorIndex = 5 
    End If 
Next