VBA find matching ID then compare other values in row

Ellie2911

New Member
Joined
May 18, 2015
Messages
4
Hello All,

I need help please. I am trying to write a macro to compare two lists with each approx 300 rows

I want to find user ID and on match compare other values in row like product code and highlight any difference.

I cannot figure out the best approach and day to day I use VLookup to compare the values but would much rather run a macro that highlights when a user ID is a match between Sheet1 and Sheet 2 but product code is different.

I hope the above makes sense.

I would appreciate any suggestion and help getting started.

Many Thanks,
Ellie
 

Some videos you may like

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

hiker95

Well-known Member
Joined
Apr 8, 2009
Messages
17,649
Ellie2911,

Welcome to the MrExcel forum.

1. What version of Excel, and, Windows are you using?

2. Are you using a PC or a Mac?

To start off, and, so that we can get it right on the first try:

Can you post screenshots of the two actual raw data worksheets?

And, can you post a screenshot of the worksheet results (manually formatted by you) that you are looking for?

To post a small screen shot (NOT a graphic, or, picture, or, flat text) try one of the following:

MrExcel HTML Maker
If you do not know how to install and how to use HTML Mr.Excel Maker
https://www.youtube.com/watch?v=JycvgGppxt0&feature=youtu.be

Excel Jeanie
Download

Borders-Copy-Paste
http://www.mrexcel.com/forum/about-board/444901-how-create-table-like-aladin.html#post2198045

To test the above:
Test Here


Or, you can upload your workbook to (the BLUE link-->) Box Net ,
sensitive data changed
mark the workbook for sharing
and provide us with a link to your workbook.
 

Ellie2911

New Member
Joined
May 18, 2015
Messages
4
Appreciate you very fast reply :)

I am on a PC
Windows 7 SP1
Excel 2010

Below is a data extract

First sheet is the source data
Second sheet is the daily file with 2 different product codes (difference manually highlighted)

image.tiff
can't seem to send the picture

Ideally I create a macro that compares the 2 files by matching User and then compare product code if different it highlights and potential adds rows that differ to new sheet.
I may want to include another compare for the Active Column but at the moment this is optional.

Let me know if you need anything else :)

Thank you
Ellie
 
Last edited:

Ellie2911

New Member
Joined
May 18, 2015
Messages
4
Sheet 1
User
Id
email addy
Active
street
Product code
Client
AB123
tom
email addy
Yes
x
0005061350
BP
CD234
****
email addy
Yes
y
1010527918
BA
DF345
harry
email addy
No
z
1000191554
Shell
FG456
John
email addy
Yes
v
1010209781
AA

<tbody id="yui_3_16_0_1_1431949638968_7357" style="width: 553px;">
</tbody>


Sheet 2


User
Id
email addy
Active
street
Product code
Client
AB123
tom
email addy
Yes
x
0005061350
BP
CD234
****
email addy
Yes
y
4509980011
BA
DF345
harry
email addy
No
z
1000191554
Shell
FG456
John
email addy
Yes
v
0983488567
AA



<tbody id="yui_3_16_0_1_1431949638968_7410" style="width: 553px;">
</tbody>
 
Last edited:

hiker95

Well-known Member
Joined
Apr 8, 2009
Messages
17,649

ADVERTISEMENT

Ellie2911,

Thanks for the screenshots.

Here is a macro solution for you to consider based on your two screenshots.

Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

1. Copy the below code
2. Open your NEW workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.

Code:
Sub Compare_ID_ProductCode()
' hiker95, 05/18/2015, ME855686
Dim w1 As Worksheet, w2 As Worksheet
Dim c As Range, a As Range
Set w1 = Sheets("Sheet1")
Set w2 = Sheets("Sheet2")
With w1
  For Each c In .Range("A2", .Range("A" & Rows.Count).End(xlUp))
    Set a = w2.Columns(1).Find(c.Value, LookAt:=xlWhole)
    If Not a Is Nothing Then
      If .Cells(c.Row, 6).Value <> w2.Cells(a.Row, 6) Then
        w2.Cells(a.Row, 6).Font.Color = vbRed
      End If
    End If
  Next c
End With
End Sub

Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm, and, answer the "do you want to enable macros" question as "yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.

Then run the Compare_ID_ProductCode macro.
 

Ellie2911

New Member
Joined
May 18, 2015
Messages
4
Hi Hiker,I am ecstatic the code worked ones I figured out I had typo. Amazing.I so appreciate your help.I am trying to learn to improve my competence I got the J Walkenbach VBA book for dummies and am planning on buying Excel 2013 Power Programming with VBA. Do you think this is a good book or do you have any recommendations?Thanks a million for you very fast help :)Regards,Ellie
 

hiker95

Well-known Member
Joined
Apr 8, 2009
Messages
17,649

ADVERTISEMENT

Ellie2911,

Hi Hiker,I am ecstatic the code worked ones I figured out I had typo. Amazing.I so appreciate your help.

Thanks a million for you very fast help

Thanks for the feedback.

You are very welcome. Glad I could help.

And, come back anytime.
 

hiker95

Well-known Member
Joined
Apr 8, 2009
Messages
17,649
Ellie2911,

I am trying to learn to improve my competence I got the J Walkenbach VBA book for dummies and am planning on buying Excel 2013 Power Programming with VBA. Do you think this is a good book or do you have any recommendations?

See if something, in the below link(s), of my most up to date list will help you:

Training / Books / Sites as of 5/19/2015

What Is VBA?
VBA is an acronym for Visual Basic for Applications. VBA should not be confused with VB, which is standard Visual Basic. Visual Basic for Applications is a programming feature designed by Microsoft for use with their Microsoft Office

MrExcel's Products: Books, CDs, Podcasts Discuss topics related to Holy Macro! Products: Learn Excel from MrExcel, VBA and Macros for Microsoft Excel,Holy Macro! It's 2500 VBA Examples CD, Guerilla Data Analysis Using Microsoft Excel and Excel Knowledge Base CD and the MrExcel Podcasts.
MrExcel's Products: Books, CDs, Podcasts

There are over 1800 Excel videos/tutorials here:
http://www.youtube.com/user/ExcelIsFun

Getting Started with VBA.
DataPig Technologies

If you are serious about learning VBA try
http://www.add-ins.com/vbhelp.htm

Excel Tutorials and Tips - VBA - macros - training
MrExcel.com | Excel Resources | Excel Seminars | Excel Products

MrExcel's Excel Tutorial Listing
MrExcel.com | Excel Resources | Excel Seminars | Excel Products

Free VBA Course
Free VBA Course

Excel 2007 VBA materials to learn here:
VBA for Excel 2007 tutorial-VBA programming?

The macro recorder actually is your friend but look here:
Beyond Excel's recorder

Introduction to Variables, Constants and Data Types
http://msdn.microsoft.com/en-us/library/aa242127(v=vs.60).aspx

Here's a good primer on the scope of variables.
Understanding Scope

Using Variables in Excel VBA Macro Code
Excel VBA Variables. Using Variables in Excel VBA Macro Code

See David McRitchie's site if you just started with VBA
Getting Started with Macros and User Defined Functions

What is a VBA Module and How is a VBA Module Used?
What Is A VBA Module and how is a VBA Module Used?

Events And Event Procedures In VBA
Events In Excel VBA

Here is a good introductory tutorial using a VBA Class:
Classes In VBA

There's a chapter on classes in VBA Developer's Handbook which is also good.
VBA Developer's Handbook, 2nd Edition: Ken Getz, Mike Gilbert: 0025211229781: Amazon.com: Books

Ron's Excel Tips
Excel for Windows Tips

Ron de Bruin's Mail from Excel and make/mail PDF files (Windows)
Mail from Excel and make/mail PDF files (Windows)

How do I create and use a PERSONAL file for my VBA code
How do I create and use a PERSONAL file for my VBA code

Anthony's Excel VBA Page - Excel Application - Excel Consultant - Excel Consulting (see 3 tutorials in Excel VBA Basic Tutorial Series)

BET: Microsoft Excel Visual Basic

Debugging VBA
Debugging VBA

Debug Excel VBA Macro Code
Debug Excel VBA Macro Code

TechBookReport - Debugging Excel VBA Code
TechBookReport - Debugging Excel VBA Code

Here are some general links on performance improvement:
https://www.soa.org/News-and-Publica...s42-roper.aspx
Optimize Slow VBA Code. Speed Up Efficient VBA Code/Macros
Excel VBA Performance Coding Best Practices - Office Blogs
https://msdn.microsoft.com/en-us/library/aa730921.aspx

Start at the beginning...

Creating An XLA Add-In For Excel, Writing User Defined Functions In VBA
Creating An XLA Add In

Build an Excel Add-In
VBA Tips: Build an Excel Add-In

Creating custom functions
http://office.microsoft.com/en-us/excel/HA011117011033.aspx

Writing Your First VBA Function in Excel
http://www.exceltip.com/st/Writing_Your_First_VBA_Function_in_Excel/631.html

VBA for Excel (Macros)
Excel Macros (VBA) Tutorial

Excel Macros Tutorial
Excel Macros (VBA) Tutorial

Excel Macros & Programming
EXCEL Macros Tutorial

VBA Lesson 11: VBA Code General Tips and General Vocabulary
http://www.excel-vba.com/vba-code-2-1-tips.htm

Excel VBA -- Adding Code to a Workbook
http://www.contextures.com/xlvba01.html

Beyond Excel's recorder

Helpful as a simple concise reference for the basics, and, using the macro recorder is endlessly powerful.
MS Excel: Cells

Learn to debug:
Debugging VBA

How To: Assign a Macro to a Button or Shape
How To: Assign a Macro to a Button or Shape - Peltier Tech Blog

User Form Creation
http://www.contextures.com/xlUserForm01.html

Build a UserForm for Excel
http://www.fontstuff.com/ebooks/free/fsuserforms.pdf

When To Use a UserForm & What to Use a UserForm For
When to use Userform & What To Use Them For. Excel Training VBA 2 lesson 2

Excel VBA how to Personalise the Ribbon
excel vba how to personalise the ribbon - Bing Videos

Excel Tutorials / Video Tutorials - Functions
http://www.contextures.com/xlFunctions02.html

How to insert Buttons, radio buttons and check boxes in Excel
How to insert Buttons, radio buttons and check boxes in Excel - Bing Videos

INDEX MATCH - Excel Index Function and Excel Match Function
http://www.contextures.com/xlFunctions03.html

Multi or two way vlook up and index match tutorial
Get Digital Help - Excel formulas, array formulas, vba, charts, pivot tables, templates and much more.

Excel Data Validation
http://www.contextures.com/xlDataVal08.html#Larger
http://www.contextures.com/excel-data-validation-add.html

Excel -- Data Validation -- Create Dependent Lists
http://www.contextures.com/xlDataVal02.html

Create dependent drop down lists containing unique distinct values in excel | Get Digital Help - Microsoft Excel resource

Your Quick Reference to Microsoft Excel Solutions
XL-CENTRAL.COM : For your Microsoft Excel Solutions

New! Excel Recorded Webinars
DataPig Technologies

Fuzzy Matching - new version plus explanation
http://www.mrexcel.com/forum/excel-questions/195635-fuzzy-matching-new-version-plus-explanation.html

Programming The VBA Editor - Created by Chip Pearson at Pearson Software Consulting LLC
This page describes how to write code that modifies or reads other VBA code.
Programming In The VBA Editor

VBA and Macros for Microsoft Excel, by Bill Jelen "Mr.Excel" and Tracy Syrstad

Excel Hacks 100 Industrial-Strength Tips & Tools, by David & Traina Hawley

VBA and Macros for Microsoft Excel 2007, by Bill Jelen "Mr.Excel" and Tracy Syrstad

John Walkenbach's power programming with Excel books.

Excel 2010 Power Programming with VBA, Mr. Spreadsheet's Bookshelf

by Stephen/ Bovey, Rob/ Green, John Bullen (Paperback - Feb 11, 2005)
Professional Excel Development

by Rob Bovey, Stephen Bullen, John Green, and Robert Rosenberg (Paperback - Sep 26, 2001)
Excel 2002 VBA: Programmers Reference

Professional Excel Development by Rob Bovey, Dennis Wallentin, Stephen Bullen, & John Green

DonkeyOte: My Recommended Reading, Volatility
Volatile Excel Functions -Decision Models

A list of Reference Books
AJP Excel Information

Sumproduct
http://www.xldynamic.com/source/xld.SUMPRODUCT.html

Arrays
VBA Array Basics
VBA Arrays
Excel: Introduction to Array Formulas - Xtreme Visual Basic Talk
Excel VBA Lesson 21: Array in Excel VBA

Array Dimensions in Visual Basic - Working with Dimensions (code and graphics)
http://msdn.microsoft.com/en-us/library/02e7z943(v=VS.80).aspx

Visual Basic Array Tutorial written by Adam Wehmann
Visual Basic Arrays Tutorial

Shortcut Keys in Excel 2000 through 2007

Pivot Intro
Using Pivot Tables in Microsoft Excel - Peltier Tech Blog
Office 2010 Class #36: Excel PivotTables Pivot Tables 15 examples (Data Analysis) - YouTube
http://www.youtube.com/watch?v=qMGILHiLqr0
Getting Started with Pivot Tables
http://www.contextures.com/xlPivot01.html#Start
Overview of PivotTable and PivotChart reports
http://office.microsoft.com/en-gb/e...table-and-pivotchart-reports-HP010342752.aspx
Build a Pivot Table in Excel VBA
Excel VBA - Build A Pivot Table In Excel VBA Tutorials

Excel 2013 PowerPivot Basics #01: Introduction To PowerPivot for Excel 2013 - YouTube

Conditional Formatting
http://office.microsoft.com/en-001/...apply-conditional-formatting-HA102809768.aspx

Email from XL - VBA
Mail from Excel example pages

Outlook VBA
Writing VBA code for Microsoft Outlook

Mail a message to each person in a range
Mail a message to each person in a range

Excel Function Dictionary by Peter Noneley
http://www.xlfdic.com/
www.xlfdic.com Excel Function Dictionary 150 example functions and formula.

Function Translations
Excel function name translations - Dictionary Chart Front Page

Dynamic Named Ranges
http://www.contextures.com/xlNames01.html

How to create Excel Dashboards
http://www.contextures.com/excel-dashboards.html
Excel Dashboards - Templates, Tutorials, Downloads and Examples | Chandoo.org - Learn Microsoft Excel Online
Excel Dashboards - Templates, Tutorials, Downloads and Examples | Chandoo.org - Learn Microsoft Excel Online
Free Microsoft Excel Dashboard Widgets to Download
Gauge

Excel Dashboard / Scorecard Ebook
Excel Dashboards and Scorecards Ebook | How to Create Dashboards in Excel

Mike Alexander from Data Pig Technologies
http://www.amazon.com/Excel-2007-Da...=sr_1_1?s=books&ie=UTF8&qid=1305564958&sr=1-1

Templates
CPearson.com Topic Index
http://www.contextures.com/excel-template-golf-scores.html
Free Microsoft Excel Template Links & Search Engine

Microsoft Excel Cascading Listboxes Tutorial
http://www.youtube.com/watch?v=YAMvLJRwZdI

Date & Time stamping:
McGimpsey & Associates : Excel : Time and date stamps

Get Formula / Formats thru custom functions:
Show FORMULA or FORMAT of another cell

A nice informative MS article "Improving Performance in Excel 2007"
http://msdn.microsoft.com/en-us/library/aa730921.aspx

Progress Meters
Progress meters
xcelfiles.com

How to convert text to numbers in Excel
http://support.microsoft.com/kb/291047

How to parse data from the web - Brett Fret has a video in YouTube
http://www.youtube.com/watch?v=6H7tBL97orE

Excel VBA MAC shortcuts
http://www.mrexcel.com/forum/excel-questions/465614-mac-shortcuts-excel.html

Macintosh Keyboard Shortcuts to use in Microsoft Excel
http://office.microsoft.com/en-us/mac-excel-help/excel-keyboard-shortcuts-HA102927337.aspx

http://office.microsoft.com/en-us/excel-help/excel-shortcut-and-function-keys-HP010073848.aspx

Excel VLOOKUP Multiple Sheets • My Online Training Hub

Wise Owl Tutorials
https://www.youtube.com/playlist?lis...3akx_gFMnpxTN5

http://msdn.microsoft.com/en-us/library/cc837974.aspx
Merging Data from Multiple Workbooks into a Summary Workbook in Excel
Merge data from all workbooks in a folder
Merging a Range from Selected Workbooks
Merging a Range from Multiple Workbooks by Column
Merging a Range from Multiple Workbooks in a Folder with a Filter

And, as your skills increase, try answering threads on sites like:
MrExcel.com | Excel Resources | Excel Seminars | Excel Products
http://www.excelforum.com
Excel Templates | Excel Add-ins and Excel Help with formulas and VBA Macros
Expert Microsoft Help, with all of the Microsoft Applications from Excel programming, Access training to our free Microsoft VBA Forums
Excel, Access, PowerPoint and Word VBA Macro Automation Help

If you are willing to spend money for the training, then something here should work for you...
http://www.amazon.com/s/?ie=UTF8&ke...vpone=&hvptwo=&hvqmt=b&ref=pd_sl_5givffg47i_b

Advanced Excel Training - Online Excel Course
http://www.udemy.com/advanced-excel/

Learn VBA Fast, Vol. I: Excel function design course, with practice exercises (The VBA Function Design Course Book 1)
Learn VBA Fast, Vol. I: Excel function design course, with practice exercises (The VBA Function Design Course Book 1) eBook: D Armstrong: Amazon.co.uk: Kindle Store

Excel VBA Programmer Interview - Excel Test for interview
Excel VBA Programmer Interview
 

LaKartoffelita

New Member
Joined
Apr 8, 2015
Messages
13
Hi everybody,

I have a similar problem, and this macro already almost works fine for me.
Instead of 2 sheets I have 4 (I managed to change the code to compare the data from all 4 sheets and use different colors for the highlighting) and instead of just one column, I need to compare every column.
In the example above only column 6 is compared - how can I change this, so every column is compared?

Thank you

(I am using PC and Excel 2007)
 

hiker95

Well-known Member
Joined
Apr 8, 2009
Messages
17,649
LaKartoffelita,

Please do not post your questions in threads started by others - - this is known as thread hijacking.

Based on your description, and, because your data set is very different, I would suggest:

That you start a new thread for your question and be sure to give it a search friendly title that accurately describes your need.

In your New Thread include:
1. What version of Excel, and, Windows are you using?
2. Are you using a PC or a Mac?
3. screenshots, NOT a picture/graphic, of the four raw data worksheets with their actual worksheet names
4. a screenshot, NOT a picture/graphic, of the results (manually formatted by you for the results you are looking for)

To post a small screen shot try one of the following:

Excel Jeanie
Download

MrExcel HTML Maker
If you do not know how to install and how to use HTML Mr.Excel Maker
https://www.youtube.com/watch?v=JycvgGppxt0&feature=youtu.be

Borders-Copy-Paste
http://www.mrexcel.com/forum/about-board/444901-how-create-table-like-aladin.html#post2198045

To test the above:
Test Here


Or, you can upload your workbook to Box Net,
sensitive data changed
mark the workbook for sharing
and provide us with a link to your workbook.


Then send me a Private Message with a link to your new thread, and, I will have a look.
 
Last edited:

Watch MrExcel Video

Forum statistics

Threads
1,122,261
Messages
5,595,126
Members
413,971
Latest member
User786

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
Top