Excel VBA: compara columns row by row

Hello experts,
I am looking for a procedure to cover the following requirements and add it to my personal.xlsb
1-Inputbox: “Enter & select the header range which is going to receive the comparison”
2-Inputbox: “Enter column letter for first comparison column”
3-Inputbox: “Enter column letter for second comparison column”
4-Perform a comparison row by row between first column and second column and reported TRUE when it is equal FASE when it is FALSE. For FALSE values report fill the various range with red colour
5-For header value related to 1- perform concatenation between header of first comparison column header & “vs” second comparison column header

I attached dummy file.

If you have questions, please contact me
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Sam JacobsDirector of Technology Development, IPMCommented:
Try this (also attached):
Option Explicit

Sub CompareColumns()

Dim strCol As String
Dim targetCol As Integer
Dim col1 As Integer
Dim col2 As Integer
Dim offset As Integer
Dim idx As Double
Dim lastrow As Double

strCol = InputBox("Please enter the column to contain the comparison results:")
If strCol = "" Then End
targetCol = Range(strCol & 1).Column
strCol = InputBox("Please enter the first column to compare:")
If strCol = "" Then End
col1 = Range(strCol & 1).Column
strCol = InputBox("Please enter the second column to compare:")
If strCol = "" Then End
col2 = Range(strCol & 1).Column

Cells(1, targetCol) = Cells(1, col1) & "vs" & Cells(1, col2)
lastrow = Cells(Rows.Count, 1).End(xlUp).Row

For idx = 2 To lastrow
    If Cells(idx, col1) = Cells(idx, col2) Then
        Cells(idx, targetCol) = "TRUE"
        Cells(idx, targetCol) = "FALSE"
        Cells(idx, targetCol).Interior.ColorIndex = 3
    End If

End Sub

Open in new window

LD16Author Commented:
Thank you for this proposal, I tested and the procedure cover almost the various requirement still pending to highlight in red values in first column comparison and second column comparison as performed in result column.
Could you please help me to adjust it?Compare-columns.png
Sam JacobsDirector of Technology Development, IPMCommented:
I'm sorry ... I don't understand what is not working correctly.
Price Your IT Services for Profit

Managed service contracts are great - when they're making you money. Yes, you’re getting paid monthly, but is it actually profitable? Learn to calculate your hourly overhead burden so you can master your IT services pricing strategy.

LD16Author Commented:
When column D is equal to FALSE, values related to column A and B should be also highlighted in red as shown in my example:
Thank you in advance for your help.
Sam JacobsDirector of Technology Development, IPMCommented:
Got it! Give me a few minutes to update...
Sam JacobsDirector of Technology Development, IPMCommented:
Updated version attached.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LD16Author Commented:
Thank you, unable to test right now. I will keep you informed.
Sam JacobsDirector of Technology Development, IPMCommented:
No problem ... thanks for the update.
LD16Author Commented:
Tested and it works! Thank you again for your help!
Sam JacobsDirector of Technology Development, IPMCommented:
You are most welcome.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.