Compare two ranges and put pass or fail

Nick70

Active Member
Joined
Aug 20, 2013
Messages
304
Office Version
  1. 365
Platform
  1. Windows
Hi,

I need a macro that compares a range in column H with a range in column E (in same sheet) and if same text then put "pass" in column F otherwise put "fail".
If cells in column H are blank then don't put anything (so either skip comparison or put """").

See example below:
Column EColumn FColumn H
JohnpassJohn
MikepassMike
Lukefail XXX
AlexpassAlex
SampassSam
LukefailXXX
DavidpassDavid
SampassSam
OscarpassOscar
ElliotfailXXX
StevepassSteve
JackpassJack


I know this can easily be done with an Excel formula but I need a macro as this VBA code will go into a larger tool that will use this function so Excel formula would be of no use.

Many Thanks,
N.
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
How about
VBA Code:
Sub Nick70()
   With Range("F2:F" & Range("H" & Rows.Count).End(xlUp).Row)
      .Value = Evaluate("if(" & .Offset(, 2).Address & "="""","""",if(" & .Offset(, 2).Address & "=" & .Offset(, -1).Address & ",""Pass"",""Fail""))")
   End With
End Sub
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0
Hi! I'm looking for something similar, but I would like to compare 2 columns in 2 different workbooks. The only output I need is:
if all cells in Column A from Workbook 1 match all cells in Column A from Workbook 2 (same order in both), then the nothing happens. If not, then the User gets an error message such as "Stop macro by pressing Esc".

Thanks in advance for all the help!

Cheers,
Tiago
 
Upvote 0
Please start a thread of your own for this. Thanks
 
Upvote 0
Oh right! Will do! I just did the same in another thread, apologies...!!
 
Upvote 0

Forum statistics

Threads
1,215,772
Messages
6,126,806
Members
449,337
Latest member
BBV123

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top