gpt4 book ai didi

excel - 通过比较两个不同的关键字来填充颜色

转载 作者:行者123 更新时间:2023-12-03 03:09:54 26 4
gpt4 key购买 nike

我想通过比较具有不同单元格文本的两列来填充整行的颜色。如下图所示,如果我在第 1 列“PAID”和第 2 列“DONE”输入。我想要整行填充绿色。

enter image description here

我的代码是:

Dim itm As Range
Dim rw As Long
With Sheets("PO 2019_Vendor")
rw = .Range("A" & .Rows.Count).End(xlUp).Row

If .Range("AG" & rw).Value = "PAID" And .Range("AJ" & rw).Value = "DONE" Then itm.EntireRow.Interior.Color = 4

If .Range("AG" & rw).Value = "PAID" And .Range("AJ" & rw).Value = "NOTRCV" Then itm.EntireRow.Interior.Color = 6

If .Range("AG" & rw).Value = "PENDING" And .Range("AJ" & rw).Value = "DONE" Then itm.EntireRow.Interior.Color = 28

End With
End Sub

希望您能理解我的解释并帮助我。预先感谢您。

最佳答案

如果该列是 AGAJ,并且标题位于第一行:

Sub erf()
Dim itm As Range
Dim rw As Long

With Sheets("PO 2019_Vendor")

rw = .Range("AG" & .Rows.Count).End(xlUp).Row

For i = 2 To rw 'only if your headers are in 1 row

If .Range("AG" & i).Value = "PAID" And .Range("AJ" & i).Value = "DONE" Then Rows(i).Interior.Color = 4

If .Range("AG" & i).Value = "PAID" And .Range("AJ" & i).Value = "NOTRCV" Then Rows(i).EntireRow.Interior.Color = 6

If .Range("AG" & i).Value = "PENDING" And .Range("AJ" & i).Value = "DONE" Then Rows(i).EntireRow.Interior.Color = 28

Next

End With

End Sub

关于excel - 通过比较两个不同的关键字来填充颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58161960/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com