Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6168281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:39:36+00:00 2026-05-23T22:39:36+00:00

Sheet1 Sheet2 Above i have two images link that i have captured from my

  • 0

Sheet1 Sheet2

Above i have two images link that i have captured from my excel document (Sheet1, Sheet 2)

Here’s a brief description basically, I just want my macros to compare Part Number (column C) from both sheets and find out the differences. And when a string differences is detected between both sheets it will highlight the row on both sheet of BOM-list to indicate to the user the differences in the Part-number(column C). But that is a problem too as seen in the images there is some rows with “space” which the loop have to take care of to prevent comparing an empty string thus giving wrong result.

Sorry for my poor command of English and explanation if its not clear to you. Can someone guide me on this i’m rather aimless on where or how to start and i have to complete this within a week without prior knowledge on excel-VBA programming understanding.

Updated:

I have updated my post can someone take a look and give me your opinion on how i can change the code to highlight the whole row of column A to P instead of column C Range value differences only?

Sub differences() 

    Dim ws1 As Worksheet, ws2 As Worksheet 
    Dim lastRow1 As Integer, lastrow2 As Integer 
    Dim rng1 As Range, rng2 As Range, temp As Range, found As Range 

    Application.ScreenUpdating = False 

    Set ws1 = ThisWorkbook.Sheets("Sheet1") 
    Set ws2 = ThisWorkbook.Sheets("Sheet2") 

    lastRow1 = ws1.Range("A" & Rows.Count).End(xlUp).Row 
    lastrow2 = ws2.Range("A" & Rows.Count).End(xlUp).Row 

    Set rng1 = ws1.Range("C21:C" & lastRow1) 
    Set rng2 = ws2.Range("C21:C" & lastrow2) 

    For Each temp In rng1 
        Set found = Find_Range(temp.Value, rng2, , xlWhole) 
        If found Is Nothing Then 
            temp.Interior.ColorIndex = 3 
        End If 
    Next temp 

    For Each temp In rng2 
        Set found = Find_Range(temp.Value, rng1, , xlWhole) 
        If found Is Nothing Then 
            temp.Interior.ColorIndex = 3 
        End If 
    Next temp 


End Sub 

Function Find_Range(Find_Item As Variant, Search_Range As Range, Optional LookIn As Variant, Optional LookAt As Variant, Optional MatchCase As Boolean) As Range 

    Dim c As Range 
    Dim firstAddress As String 

    If IsMissing(LookIn) Then LookIn = xlValues 'xlFormulas
    If IsMissing(LookAt) Then LookAt = xlPart 'xlWhole
    If IsMissing(MatchCase) Then MatchCase = False 

    With Search_Range 
        Set c = .Find(What:=Find_Item, LookIn:=LookIn, LookAt:=LookAt, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=MatchCase, SearchFormat:=False) 
        If Not c Is Nothing Then 
            Set Find_Range = c 
            firstAddress = c.Address 
            Do 
                Set Find_Range = Union(Find_Range, c) 
                Set c = .FindNext(c) 
            Loop While Not c Is Nothing And c.Address <> firstAddress 
        End If 
    End With 
End Function 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T22:39:37+00:00Added an answer on May 23, 2026 at 10:39 pm

    As I cant see the the images, I will make the assumption that what you are trying to do is check if a part number exists in the other list and if not then highlight it.

    Off the top of my head this is what you will basically need to do.

    Public Sub Test()
        CompareRange Sheet1.Range("A2", "A8"), Sheet2.Range("A2", "A8")
    End Sub
    
    
    Public Sub CompareRange(range1 As Range, range2 As Range)
        Dim CompareCell As Range
        Dim CheckCell As Range
        Dim CellFound As Boolean
        For Each CompareCell In range1.Cells
            CellFound = False
            For Each CheckCell In range2.Cells
    
                If CheckCell.Text = CompareCell.Text Then
                    CellFound = True
                End If
            Next CheckCell
            If Not CellFound Then
                CompareCell.Interior.Color = vbYellow
            End If
        Next CompareCell
    End Sub
    

    One thing to note is that this function assumes that you have a single column range. otherwise it will check all the cells in your ranges and probably highlight more than you intended.

    EDIT
    As far as Highlighting the Row
    try adding this to your find loop

    Dim CompareSheet as Worksheet 'Add at top of function
    
    'Add to the For Each Loop
    Set CompareSheet = temp.Worksheet
    CompareSheet.Range("A" & temp.Row, "P" & temp.Row).Interior.ColorIndex = 3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one Excel document with two sheets Sheet1 and Sheet2. Sheet1 data is
I have an excel document with multiple sheets. Each sheet contains data of separate
I have an Action Sheet that is called from my root view controller using
I have an iframe that I use to display HTML pages published from Excel.
I have get the date from excel sheet using POI using the below code,
I have a web application that generates two different Excel reports with different numbers
VBA is throwing the above given error on the line Sheets(Sheet1).Range(A & i).Copy Destination:=Sheets(Sheet2).Range(A
I have sheet1.xls which is closed. I am working in sheet2.xls VBA as follows.
Cell A1: =HYPERLINK(#Sheet2!a2,link) Sheet->View Code Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink) MsgBox (hello) End
i have two sheets having data like this sheet1 : **A** **B** **C** 752

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.