【发布时间】:2021-05-07 15:19:42
【问题描述】:
我有一张关于订单详情的表格。在 G 列中,一个特定的值表示订单包装在哪个容器(运输容器)中。screenshot
- 我想要所有重复的容器号。用不同的颜色和它们所在的行突出显示。
含义:当我有“容器号 X”时,连接到 X 的整行是一种颜色,连接到“容器号 Y”的行是另一种颜色等等。
-
我还希望在某些内容发生变化或点击数据栏中的“更新值”时自动更新颜色
-
G 列的空白单元格不应着色。
这可能吗?如果可以,有人可以帮助我吗?我是 VBA 的初学者。
Sub ColorCompanyDuplicates()
'Updateby Extendoffice
Dim xRg As Range
Dim xTxt As String
Dim xCell As Range
Dim xChar As String
Dim xCellPre As Range
Dim xCIndex As Long
Dim xCol As Collection
Dim I As Long
On Error Resume Next
If ActiveWindow.RangeSelection.Count > 1 Then
xTxt = ActiveWindow.RangeSelection.AddressLocal
Else
xTxt = ActiveSheet.UsedRange.AddressLocal
End If
Set xRg = Application.InputBox("please select the data range:", "Kutools for Excel", xTxt, , , , , 8)
If xRg Is Nothing Then Exit Sub
xCIndex = 2
Set xCol = New Collection
For Each xCell In xRg
On Error Resume Next
If xCell.Value <> "" Then
xCol.Add xCell, xCell.Text
If Err.Number = 457 Then
xCIndex = xCIndex + 1
Set xCellPre = xCol(xCell.Text)
If xCellPre.Interior.ColorIndex = xlNone Then xCellPre.Interior.ColorIndex = xCIndex
xCell.Interior.ColorIndex = xCellPre.Interior.ColorIndex
ElseIf Err.Number = 9 Then
MsgBox "Too many duplicate companies!", vbCritical, "Kutools for Excel"
Exit Sub
End If
On Error GoTo 0
End If
Next
End Sub
【问题讨论】:
-
欢迎您,看来您希望我们制作您的作品。上传您的尝试。如果您可以上传工作表的图像,这也会很有用。描述写得很糟糕。容器是什么意思?
-
谢谢!我已经编辑了我写得不好的描述,并添加了一张纸片。集装箱,我的意思是集装箱。我之前的尝试是在描述中,但是这只会突出显示 G 列中的重复项,并且必须在进行更改时运行。
-
好多了@maka
标签: excel vba colors duplicates