I have 2 data sets in 2 different worksheets and I'm trying to find out which account/s that have a different Yes/No to the main data source based on matching customer number and bucket.
For instance: assuming the table starts from cell A1 , so I need to highlight the cells: C7,C13,C14 and C15 because the same matching customer number and buckets in table B are Yes.
我在两个不同的工作表中有两个数据集,我正在根据匹配的客户编号和存储桶,尝试找出哪个帐户/S对主数据源具有不同的Yes/No。例如:假设表格从单元格A1开始,因此我需要突出显示单元格:C7、C13、C14和C15,因为表B中相同的匹配客户编号和存储桶为Yes。
Is there away to achieve this, please?
请问有没有办法做到这一点?
Thank you
谢谢
Table A
表A
Customer Number |
Buckets |
Yes/No |
55850 |
1-30 |
Yes |
55850 |
30-60 |
Yes |
55850 |
60-90 |
Yes |
55850 |
90-120 |
Yes |
55850 |
120-180 |
Yes |
32336 |
30-60 |
No |
32336 |
60-90 |
Yes |
30131 |
1-30 |
Yes |
30131 |
30-60 |
Yes |
30131 |
60-120 |
Yes |
13914 |
1-30 |
Yes |
13914 |
30-60 |
No |
13914 |
60-90 |
No |
13914 |
90-120 |
No |
Table B
表B
Customer Number |
Buckets |
Yes/No |
13914 |
1-30 |
Yes |
13914 |
30-60 |
Yes |
13914 |
60-90 |
Yes |
13914 |
90-120 |
Yes |
30131 |
1-30 |
Yes |
30131 |
30-60 |
Yes |
30131 |
60-120 |
Yes |
32336 |
30-60 |
Yes |
32336 |
60-90 |
Yes |
55850 |
1-30 |
Yes |
55850 |
30-60 |
Yes |
55850 |
60-90 |
Yes |
55850 |
90-120 |
Yes |
55850 |
120-180 |
Yes |
55851 |
120-181 |
Yes |
55852 |
120-182 |
Yes |
55853 |
120-183 |
Yes |
55854 |
120-184 |
Yes |
55855 |
120-185 |
Yes |
55856 |
120-186 |
Yes |
55857 |
120-187 |
Yes |
55858 |
120-188 |
Yes |
55859 |
120-189 |
Yes |
55860 |
120-190 |
Yes |
55861 |
120-191 |
Yes |
55862 |
120-192 |
Yes |
55863 |
120-193 |
Yes |
55864 |
120-194 |
Yes |
55865 |
120-195 |
Yes |
55866 |
120-196 |
Yes |
55867 |
120-197 |
Yes |
更多回答
I would look at using index() with match() with a simple compare
我将使用index()和Match()进行简单的比较
@SolarMike Thanks for that but the actual data is quite large and using the index/match takes long time. I wanted to get it efficiently by using array and reserve the values from table A and then loop in table B to compare with the data preserves from table A, but couldn’t get that right. Specially with joining the 3 columns of table A and start compare with split columns in table B.
@SolarMike对此表示感谢,但实际数据相当大,使用索引/匹配需要很长时间。我想通过使用数组并保留表A中的值,然后在表B中循环以与表A中保留的数据进行比较来有效地获取它,但无法正确完成。特别是连接表A的3列,并开始与表B中的拆分列进行比较。
So, show what you attempted and people may help improve it.
所以,展示你的尝试,人们可能会帮助你改进它。
so I need to highlight the cells - in which table A, B or both.
因此,我需要突出显示单元格--表格A和/或表格B。
in table A only. Table B is the data source to compare with.
仅限于A表。表B是要比较的数据源。
优秀答案推荐
Use a Dictionary object, join columns A and B to create the unique key.
使用字典对象,联接列A和列B来创建唯一键。
Option Explicit
Sub compareAB()
Dim arB, cel As Range, i As Long
Dim dict As Object, k As String, n As Long
Dim t0 As Single: t0 = Timer
Set dict = CreateObject("Scripting.Dictionary")
' read table B into dictionary
arB = Range("Table B").Value2
For i = 1 To UBound(arB)
k = arB(i, 1) & ";" & arB(i, 2)
If dict.exists(k) Then
MsgBox "Duplicate key " & k & " on row " & i, vbCritical
Exit Sub
ElseIf Len(k) > 1 Then
dict.Add k, arB(i, 3)
End If
Next
'Dim ky: For Each ky In dict.keys: Debug.Print ky, dict(ky): Next
' highlight diff in Table A
Application.ScreenUpdating = False
With Range("Table A").Columns(3)
.Interior.Pattern = xlNone
For Each cel In .Cells
k = cel.Offset(, -2).Value2 & ";" & cel.Offset(, -1).Value2
If dict.exists(k) Then
If dict(k) <> cel.Value2 Then
cel.Interior.Color = RGB(255, 255, 0) ' yellow
n = n + 1
End If
End If
Next
End With
Application.ScreenUpdating = True
MsgBox n & " rows highlighted in Table A", _
vbInformation, Format(Timer - t0, "0.0 secs")
End Sub
更多回答
我是一名优秀的程序员,十分优秀!