Hello,
I'm here today because I don't know how to change this on my own.
I would like to build 2 macros using the one here as reference one for the list combined and the other for the duplicates.
1) List combined: Compare columns, where the size of each can vary, leave the duplicates on one and reorganize the results based on the
total count of the values left.
a) Instead of only compare just two columns (1 on 1), like most requests, I'd like the option to compare any number of columns changing this.
This part here, if I want to compare 2 on 2 columns, this code only works properly if the longer column is A.
b) The order of organization is in the same sequence as the first(s) column(s);
Example:
If I'm comparing just two columns A and B, the sequence would be column A going down to the last cell.
If I'm comparing 2 on 2 columns (A:B with C:D), the sequence starts on A goes down to the last cell and then goes up to B and goes down
again until the last cell.
c) After that comparison, reorganize everything this way:
If the total count of the values left is an even number, put the first half on one column and second half on the adjacent;
If the total count of the values left is an odd number, put the first half + 1 one column and second half on the adjacent.
2) Duplicates: Do everything as above but for the duplicates ones.
Thank you for the help.
LC = List Combined
D = Duplicates
I put the coditioning to be easier to see.
I'm here today because I don't know how to change this on my own.
I would like to build 2 macros using the one here as reference one for the list combined and the other for the duplicates.
1) List combined: Compare columns, where the size of each can vary, leave the duplicates on one and reorganize the results based on the
total count of the values left.
a) Instead of only compare just two columns (1 on 1), like most requests, I'd like the option to compare any number of columns changing this.
VBA Code:
ListARange = Cells(Rows.Count, "A").End(xlUp).Row 'find the last row with data on column A
ListBRange = Cells(Rows.Count, "B").End(xlUp).Row 'find the last row with data on column B
b) The order of organization is in the same sequence as the first(s) column(s);
Example:
If I'm comparing just two columns A and B, the sequence would be column A going down to the last cell.
If I'm comparing 2 on 2 columns (A:B with C:D), the sequence starts on A goes down to the last cell and then goes up to B and goes down
again until the last cell.
c) After that comparison, reorganize everything this way:
If the total count of the values left is an even number, put the first half on one column and second half on the adjacent;
If the total count of the values left is an odd number, put the first half + 1 one column and second half on the adjacent.
2) Duplicates: Do everything as above but for the duplicates ones.
Thank you for the help.
VBA Code:
Sub compare()
Dim ListA As Range
Dim ListB As Range
Dim c As Range
ListARange = Cells(Rows.Count, "A").End(xlUp).Row 'find the last row with data on column A
ListBRange = Cells(Rows.Count, "B").End(xlUp).Row 'find the last row with data on column B
Set ListA = Range("A2:A" & ListARange) 'set your range only until the last row with data
Set ListB = Range("B2:B" & ListBRange)
Application.ScreenUpdating = False
Range("C1").Value = "Files in A that are NOT in B"
Range("D1").Value = "Files in B that are Not in A"
Range("E1").Value = "Matching Files"
For Each c In ListA
If Application.CountIf(ListB, c) = 0 Then
Cells(Cells(Rows.Count, "C").End(xlUp).Row + 1, "C").Value = c
ElseIf Application.CountIf(ListB, c) >= 1 Then
Cells(Cells(Rows.Count, "E").End(xlUp).Row + 1, "E").Value = c
End If
Next c
For Each c In ListB
If Application.CountIf(ListA, c) = 0 Then Cells(Cells(Rows.Count, "D").End(xlUp).Row + 1, "D").Value = c
Next c
Application.ScreenUpdating = True
End Sub
LC = List Combined
D = Duplicates
I put the coditioning to be easier to see.
Comparison.xlsm | ||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | AA | AB | AC | AD | AE | AF | AG | AH | AI | AJ | AK | AL | AM | AN | |||
1 | LC | 1 | on | 1 | LC | 2 | on | 2 | D | 1 | on | 1 | D | 2 | on | 2 | ||||||||||||||||||||||||||
2 | ||||||||||||||||||||||||||||||||||||||||||
3 | 37 | 60 | 37 | 22 | 36 | 60 | 1 | 27 | 36 | 6 | 41 | 17 | 44 | 17 | 37 | 15 | 33 | 37 | 37 | 30 | ||||||||||||||||||||||
4 | 30 | 44 | 30 | 20 | 31 | 6 | 10 | 25 | 31 | 56 | 44 | 16 | 40 | 56 | 35 | 10 | 30 | 39 | 35 | 59 | ||||||||||||||||||||||
5 | 10 | 40 | 10 | 9 | 32 | 56 | 11 | 29 | 32 | 16 | 40 | 15 | 4 | 50 | 32 | 18 | 37 | 36 | 32 | 55 | ||||||||||||||||||||||
6 | 18 | 45 | 18 | 60 | 39 | 16 | 18 | 20 | 39 | 15 | 1 | 57 | 14 | 55 | 27 | 17 | 7 | 60 | 25 | 50 | ||||||||||||||||||||||
7 | 17 | 41 | 17 | 44 | 42 | 15 | 17 | 23 | 42 | 51 | 4 | 56 | 15 | 57 | 25 | 38 | 6 | 49 | 28 | 5 | ||||||||||||||||||||||
8 | 48 | 10 | 48 | 15 | 43 | 51 | 60 | 30 | 43 | 2 | 14 | 50 | 45 | 28 | 30 | 60 | 40 | 26 | 43 | |||||||||||||||||||||||
9 | 41 | 15 | 41 | 4 | 48 | 2 | 3 | 35 | 48 | 1 | 11 | 55 | 26 | 59 | 39 | 45 | 43 | 49 | ||||||||||||||||||||||||
10 | 8 | 18 | 8 | 5 | 18 | 1 | 6 | 50 | 18 | 11 | 10 | 54 | 43 | 54 | 9 | 41 | 41 | 45 | ||||||||||||||||||||||||
11 | 7 | 17 | 7 | 53 | 17 | 11 | 16 | 54 | 17 | 29 | 7 | 59 | 41 | 55 | 3 | 10 | 58 | 53 | ||||||||||||||||||||||||
12 | 16 | 49 | 16 | 58 | 13 | 29 | 19 | 59 | 13 | 28 | 18 | 60 | 58 | 50 | 31 | 15 | 53 | 58 | ||||||||||||||||||||||||
13 | 19 | 9 | 19 | 42 | 12 | 28 | 39 | 4 | 12 | 26 | 15 | 3 | 52 | 4 | 32 | 14 | 33 | 33 | ||||||||||||||||||||||||
14 | 52 | 4 | 52 | 43 | 27 | 26 | 31 | 5 | 27 | 10 | 48 | 6 | 53 | 5 | 35 | 6 | 31 | 32 | ||||||||||||||||||||||||
15 | 50 | 5 | 50 | 39 | 23 | 36 | 45 | 23 | 3 | 45 | 4 | 33 | 8 | 20 | 9 | 14 | 39 | |||||||||||||||||||||||||
16 | 55 | 54 | 55 | 38 | 25 | 15 | 44 | 25 | 19 | 12 | 46 | 31 | 47 | 25 | 5 | 22 | 36 | |||||||||||||||||||||||||
17 | 59 | 55 | 59 | 36 | 33 | 55 | 48 | 33 | 52 | 17 | 44 | 34 | 43 | 16 | 59 | 20 | 2 | |||||||||||||||||||||||||
18 | 54 | 53 | 54 | 33 | 35 | 52 | 49 | 35 | 57 | 56 | 49 | 11 | 49 | 13 | 55 | 15 | 22 | |||||||||||||||||||||||||
19 | 40 | 58 | 40 | 28 | 30 | 57 | 58 | 30 | 7 | 53 | 45 | 14 | 45 | 12 | 50 | 10 | ||||||||||||||||||||||||||
20 | 49 | 42 | 49 | 25 | 38 | 2 | 42 | 38 | 20 | 50 | 21 | 22 | 53 | 26 | 22 | |||||||||||||||||||||||||||
21 | 45 | 43 | 45 | 50 | 7 | 9 | 50 | 54 | 55 | 25 | 20 | 58 | 23 | 28 | ||||||||||||||||||||||||||||
22 | 22 | 59 | 58 | 58 | 59 | 57 | 23 | 33 | 22 | |||||||||||||||||||||||||||||||||
23 | 20 | 39 | 55 | 55 | 4 | 52 | 31 | 32 | 2 | |||||||||||||||||||||||||||||||||
24 | 9 | 38 | 53 | 53 | 45 | 20 | 40 | 39 | 5 | |||||||||||||||||||||||||||||||||
25 | 36 | 8 | 8 | 44 | 27 | 43 | 36 | 50 | ||||||||||||||||||||||||||||||||||
26 | 33 | 5 | 5 | 49 | 28 | 14 | 2 | |||||||||||||||||||||||||||||||||||
27 | 28 | 60 | 9 | 36 | 9 | 22 | ||||||||||||||||||||||||||||||||||||
28 | 25 | 39 | 29 | |||||||||||||||||||||||||||||||||||||||
Plan1 |
Cells with Conditional Formatting | ||||
---|---|---|---|---|
Cell | Condition | Cell Format | Stop If True | |
AF3:AJ28 | Cell Value | duplicates | text | NO |
X3:Y28 | Cell Value | duplicates | text | NO |
J22:M26,N23:N26,O22:O26,J3:N21 | Cell Value | duplicates | text | NO |
B22:F28,B3:D21 | Cell Value | duplicates | text | NO |