簡體   English   中英

如果語句要檢查Excel列中的匹配值

[英]If Statement to check Excel column for a match value

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

偽代碼示例:

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

我知道如何更改背景的部分,但是檢查給定范圍的最佳方法是什么?

我猜您可能在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

我想你想要類似的東西

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM