在数据透视表中突出显示同一列中的差异

我创build了一个列A和列B的数据透视表。列A与列B有一对多的关系。

如果在其范围内的列B值有所不同,我想突出显示列A。 例如,

AB ABC 10 10 XYZ 20 25 

在这种情况下,XYZ在B列中有2个不同的值。我想强调这一点。 这怎么能在excel中完成呢?

干杯!!

这里是你如何使用VBA来做到这一点

 Private Sub CommandButton8_Click() Dim WS As Excel.Worksheet Dim lRow As Long Dim lastRow As Long Dim ValueB As String Dim lRowA As Long Set WS = Application.Sheets("Sheet1") lRow = 1 'Get the last row that has data in columnB lastRow = WS.Cells(WS.Rows.Count, "B").End(xlUp).Row 'Loop through all the rows Do While lRow <= lastRow 'If we have data in columnA, record it If WS.Range("A" & lRow).Value <> "" Then ValueB = WS.Range("B" & lRow).Value 'Keep track of the row that we found new columnA data on lRowA = lRow Else 'We don't have data in columnA, Compare what we found in 'columnB of the last row where we had data in columnA with this row If ValueB <> WS.Range("B" & lRow).Value Then WS.Range("A" & lRowA).Interior.Pattern = xlSolid WS.Range("A" & lRowA).Interior.PatternColorIndex = xlAutomatic WS.Range("A" & lRowA).Interior.Color = 255 End If End If lRow = lRow + 1 WS.Range("A" & lRow).Activate Loop End Sub