2
I’m having trouble creating a macro that can check the equality between each cell of a list and, if both are different, leave a blank line above the cell.
For example:
TO THE
B C
C D
D AND
AND F
G H
Leaving:
TO THE
B
C C
D
AND AND
F
G
H
I have to check if the two lists of names are equal, and for each error I have to make a notification (hence the empty cell). I can’t mix up the mistakes on each list.
The Code I have so far is somewhat discouraging.
Private Sub compare_cells(ByVal Target1 As Range, ByVal Target2 As Range)
If Target1 Is Nothing Then Exit Sub
If Target2 Is Nothing Then Exit Sub
Dim ws1, ws2 As Worksheet
Set ws1 = Sheets(Target1.Parent.Name)
Set ws2 = Sheets(Target2.Parent.Name)
If Target1.Value <> Target2.Value Then
' If they don't match place your code here
ws1.Range(Target1.Row & ":" & Target1.Row).Insert Shift:=xlDown
ws2.Range(Target2.Row & ":" & Target2.Row).Insert Shift:=xlDown
End If
End Sub
I was trying to make it work that way:
Range("A3:C3").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Cut
Range("A4").Select
ActiveSheet.Paste
Range("B4").Select
But I’m having a hard time doing that.
This macro did not work in the example above, it creates a new line with all the data of the two lists together and moves the other lists to the right. What can I do?
– paulmuaddib
Did you copy the whole thing down to the "end sub" part? First she does what she mentioned, then eliminates duplicates and organizes, and in the end excludes the new line, leaving only the desired result. Try again!
– tsachetto
I tried again and used the debugger. In it, the code hangs on
ActiveWorkbook.Worksheets(planilha).Sort.SortFields.Add2 Key:=Range("A1") _
 , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNorma
– paulmuaddib
Friend, I changed the macro. I imagine I have already solved. But I had to travel, only today I returned to excel. Abs
– tsachetto