473,804 Members | 2,164 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

EXCEL: Highlight duplicate records from different spreadsheets in the same workbook

16 New Member
I need to make a macro that finds duplicate records in Column A in sheet1 and Column A in sheet2. If there is a duplicate I need both to be highlighted in red. If there is no duplicate in Column A sheet1 then color that record green. If there is no duplicate in Column A sheet2 color that record yellow.

the sample data is:
Sheet1
CONTAINER
ABC123
ABC234
ABC345
ABC456

Sheet2
CONTAINER
ABC234
DFC123
ABC456
AET432

as you can see some of the data matches and some don't

Please help never made a macro in Excel before.
Mar 19 '10 #1
1 2353
jerelp
16 New Member
I have code for a single column on one spreadsheet but, how can i manipulate it to do what I need it to do

Expand|Select|Wrap|Line Numbers
  1. Sub TestForDups()
  2.  
  3.     Dim LLoop As Integer
  4.     Dim LTestLoop As Integer
  5.     Dim LClearRange As String
  6.  
  7.     Dim Lrows As Integer
  8.     Dim LRange As String
  9.     Dim LChangedValue As String
  10.     Dim LTestValue As String
  11.  
  12.     'Test first 200 rows in spreadsheet for uniqueness
  13.     Lrows = 500
  14.     LLoop = 2
  15.  
  16.     'Clear all flags
  17.     LClearRange = "A2:A" & Lrows
  18.     Range(LClearRange).Interior.ColorIndex = xlNone
  19.  
  20.     'Check first 500 rows in spreadsheet
  21.     While LLoop <= Lrows
  22.         LChangedValue = "A" & CStr(LLoop)
  23.  
  24.         If Len(Range(LChangedValue).Value) > 0 Then
  25.  
  26.             'Test each value for uniqueness
  27.             LTestLoop = 2
  28.             While LTestLoop <= Lrows
  29.                 If LLoop <> LTestLoop Then
  30.                     LTestValue = "A" & CStr(LTestLoop)
  31.                     'Value has been duplicated in another cell
  32.                     If Range(LChangedValue).Value = Range(LTestValue).Value Then
  33.                         'Set the background color to red
  34.                         Range(LChangedValue).Interior.ColorIndex = 3
  35.                         Range(LTestValue).Interior.ColorIndex = 3
  36.  
  37.                     End If
  38.  
  39.                 End If
  40.  
  41.                 LTestLoop = LTestLoop + 1
  42.  
  43.             Wend
  44.  
  45.         End If
  46.  
  47.         LLoop = LLoop + 1
  48.     Wend
  49.  
  50. End Sub
  51.  
Mar 19 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
11314
by: RK | last post by:
Hi, In my application, I need to copy data from an Excel file into a SQL table. The article related to this can be found at http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3B306572 Using this,I am first extracting data from given excel file into a temporary DataTable. After making some operations on that DataTable (like splitting one column into two), I am saving the data into actual
2
2011
by: Jason H | last post by:
Okay, here is my problem and understand I have little experience with Access. I am trying to integrate 3 spreadsheets into Access. Each spread sheet is about 50 legal pages in size and are linked by a persons name. What I need is a way to do this enormous task. Here is an idea of what I have, Spreadsheet 1 looks like; A1 B1
11
4060
by: Mr. Smith | last post by:
Hello all, My code can successfully open, write to, format and save several worksheets in a workbook then save it by a given name, close and quit excel. My problem is that if I try and do it again, Excel hangs. OR if I open Excel again (say from a desktop icon) before I close Access, Excel hangs. (this has happened for both 97 & 2000 for me) I of course thought that I mustn't be unloading a variable properly.
0
2254
by: Rich Wallace | last post by:
Hello all, Looking for suggestions and tips if possible. I have an application running on a file server that utilizes the FileSystemWatcher to trap when any Excel files are saved by a user. I then need to 'trap' the current file and generate an XML file from the data within the active spreadsheet. I have two issues so far with doing this... Issue 1: Once a file that is being watched is saved, I grab it using the
9
2828
by: Anthony | last post by:
To me, creating Excel 2003 spreadsheets programmatically via VB.NET hasn't really changed since the days of VB6. That is, I'd do something similar to this Code: Dim ExcelApp As Excel.Application Dim ExcelWB As Excel.Workbook
2
2319
by: Jim S | last post by:
To my surprise and chagrin, newer versions of Access have disabled the functionality that lets users change the data in linked tables that point to a range in an Excel workbook. This is "because of legal issues..." according to Office Support. I have other issues, specifically a couple of applications that do things such as calculate price updates in Access and read them back by means of update queries into the spreadsheets our marketing...
21
6251
by: bobh | last post by:
Hi All, In Access97 I have a table that's greater than 65k records and I'm looking for a VBA way to export the records to Excel. Anyone have vba code to export from access to excel and have the code use multiple excel tabs within a workbook???? Anyone have vba code that would create a temp table write 65,000 records to it, export those to excel, clean the temp table, append the next 65,000 records, export it to excel with a different...
1
1218
by: shutterlug | last post by:
Hello Everyone, I'm in the middle of what has turned into a very strange project. I am desperate and could use some help. Here are the circumstances: - The company I'm working for uses Excel '02. - I was initially asked to do this as an Access DB, but... - Data comes from a web-based report generator into an Excel workbook, so why go with Access, especially when no one in the office knows how to use it... - Generated workbook has a...
11
5785
by: bbasberg | last post by:
Hello, I have been struggling with this problem for DAYS and have googled my heart out as well as reading any books I could get my hands on but I cannot find any specific references to my problem. I have been able to successfully loop through a directory reading spreadsheets that insert records into an Access database. The spreadsheets in said directory are all of the same format but have different values in the cells. It's when I turned...
2
3213
by: ravir81 | last post by:
Hi, I am working on excel reporting using Perl. I am facing problem with writing the header part only once for all the excels created using Perl. Here is the code : #!/usr/local/bin/perl use strict; use Spreadsheet::ParseExcel;
0
9594
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10350
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10351
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9174
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5534
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4311
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3834
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3002
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.