Hello, I am trying to write a macro and am confusing myself. Please help.
The macro should do the following:
1) Compare all cells with data, in Column A to all cells with data to column C.
2) Compare all combinations of cells from Columns A & B (i.e. A1 with B1, and so on) to combinations of cells from Columns C & D (i.e. C1 with D1).
3) All cells that are in Column A but not in Column C should be pasted into sheet 2, column A, with red font.
4) All cells that are in Column C but not in Column A should be pasted into sheet 2, column B, with red font.
5) All combination cells that have same first column (columns A & C must match) but a different value in combination cell of column B and column D should be pasted into sheet 2, column C, with red font.
Unfortunately, I am quite new to writing macros, and it has been quite some time since I've touched VBA. I don't think I'm coming anywhere near to writing a VBA for what I want it to do. I also played around with the idea of a message box, but when I tested the macro it locked up excel.
All help is greatly appreciated! Thanks!
Sub CompareContrast()
Dim t As Integer
Dim u As Integer
Dim x As Integer
Dim y As Integer
Set RngA = Range("A1", Range("A1").End(xlDown))
Set RngB = Range("B1", Range("B1").End(xlDown))
Set RngC = Range("C1", Range("C1").End(xlDown))
Set RngD = Range("D1", Range("D2").End(xlDown))
For Each cell In RngA
If x = y Then MsgBox "All CPT match" Else Sheets("Sheet2").Range("A:A").Copy Range("A1")
If t = u Then MsgBox "All match" Else Sheets("Sheet2").Range("B:B").Copy Range("B1")
Next cell
Sheets("Sheet2").Activate
Range("A1", Range("A1").End(xlDown)).Font.red = True
Range("B1", Range("B1").End(xlDown)).Font.red = True
Range("C1", Range("C1").End(xlDown)).Font.red = True
End Sub
Bookmarks