+ Reply to Thread
Results 1 to 8 of 8

Create report compareing 2 Sheets

Hybrid View

  1. #1
    Registered User
    Join Date
    05-12-2009
    Location
    qc
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Create report compareing 2 Sheets

    Sub compare_two_column1()



    lastrow& = Sheets(1).Cells.find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
    i = 1
    Do Until lastrow = i
    Tag = Worksheets(1).Cells(i, 1)

    Set c = Worksheets(1).Range("b1", Worksheets(1).Cells(lastrow, 2)).find(Tag, LookIn:=xlValues)
    If c Is Nothing Then
    Worksheets(1).Cells(i, 1).Interior.Color = vbYellow
    End If

    i = i + 1


    Loop
    End Sub

    Sub compare_two_column2()



    lastrow& = Sheets(1).Cells.find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
    i = 1
    Do Until lastrow = i
    Tag = Worksheets(1).Cells(i, 2)

    Set c = Worksheets(1).Range("a1", Worksheets(1).Cells(lastrow, 1)).find(Tag, LookIn:=xlValues)
    If c Is Nothing Then
    Worksheets(1).Cells(i, 2).Interior.Color = vbYellow
    End If

    i = i + 1


    Loop
    End Sub



    compare two column and put some color on diffference if it not find

  2. #2
    Registered User
    Join Date
    04-27-2009
    Location
    Bahrain
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Create report compareing 2 Sheets

    wow, that looks good. I have the names in 2 different sheets, but i think i can figure that out.
    Thank you verry much for your response!
    I'm back to testing

  3. #3
    Registered User
    Join Date
    05-12-2009
    Location
    qc
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Create report compareing 2 Sheets

    i just find for you this function

    ActiveWindow.SelectedSheets

    so u can select two sheet from sheet tab (tab name) at the bottom with ctrl button and mouse. So you don't to enter in the vba to change sheet name

    
    sheet1_name = ActiveWindow.SelectedSheets.Item(1).CodeName
    sheet2_name = ActiveWindow.SelectedSheets.Item(2).CodeName

  4. #4
    Registered User
    Join Date
    04-27-2009
    Location
    Bahrain
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Create report compareing 2 Sheets

    just tested the code you gave me, works like hell

    Sub compare_two_sheets()
    'mark green who is new on the list (sheet1)
    lastrow1& = Sheets(1).Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
    lastrow2& = Sheets(2).Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
    i = 2
    Do Until lastrow1& = i
    Tag = Worksheets(1).Cells(i, 2)
    Set c = Worksheets(2).Range("b2", Worksheets(2).Cells(lastrow2&, 2)).Find(Tag, LookIn:=xlValues)
    If c Is Nothing Then
    Worksheets(1).Cells(i, 2).Interior.Color = vbGreen
    End If
    i = i + 1
    Loop
    
    'mark red who dropped out the list (sheet2)
    r = 2
    Do Until lastrow1& = r
    Tag = Worksheets(2).Cells(r, 2)
    Set c = Worksheets(1).Range("b2", Worksheets(1).Cells(lastrow1&, 2)).Find(Tag, LookIn:=xlValues)
    If c Is Nothing Then
    Worksheets(2).Cells(r, 2).Interior.Color = vbRed
    End If
    r = r + 1
    Loop
    End Sub
    Thank you, you saved my night! The "selctedsheet" is another big help.

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Create report compareing 2 Sheets

    fou, please edit your post to add code tags.
    Entia non sunt multiplicanda sine necessitate

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1