Consulting

Results 1 to 9 of 9

Thread: Macro for comparing cells on 2 sheets in Excel

  1. #1

    Macro for comparing cells on 2 sheets in Excel

    I need some help writing a macro that basically compares 2 data reports.
    -Each week I get an updated report, so the columns are all formatted identically.
    -I just need to determine which sku's are new over the previous week.
    -The column that I'd like to sort on is SKU. Id like to have a 3rd sheet created that only shows the new entries.

    I'm sure this is a pretty easy one, but I'm a newbie when it comes to writing macros.

    Greatly appreciate the help!

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Can you post a sample file showing your data layout?
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3

    sample workbook

    here's a sample worksheet.
    -need to compare the column "SKU"
    -worksheet "Unique" will show the uniques
    Last edited by jasonr704; 05-07-2010 at 04:32 PM.

  4. #4
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Nothing attached.
    Use Manage Attachments in the Go Advanced reply section
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    i also need this macro

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Sub IDENTIFY_duplicates()
    Dim i As Long
    Dim LastRow As Long
    Dim NextRow As Long

    With Worksheets("week2")

    LastRow = .Cells(.Rows.Count, "B").End(xlUp).Row
    NextRow = 1
    For i = 2 To LastRow

    If IsError(Application.Match(.Cells(i, "B").Value2, Worksheets("week1").Columns("B"), 0)) Then

    NextRow = NextRow + 1
    .Rows(i).Copy Worksheets("uniques").Cells(NextRow, "A")
    End If
    Next i
    End With
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  7. #7
    Thanks for the code. Seems to work, but it's taking a long long time to complete. I have fewer than 100,000 rows of data with less than 12 columns of data. is there a way to speed this macro up any?

  8. #8
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    This might be somewhat quicker

    [vba]

    Sub IDENTIFY_duplicates()
    Dim i As Long
    Dim LastRow As Long
    Dim NextRow As Long

    With Application

    .ScreenUpdating = False
    .Calculation = xlCalculationManual
    End With

    With Worksheets("week2")

    LastRow = .Cells(.Rows.Count, "B").End(xlUp).Row
    NextRow = 1
    For i = 2 To LastRow

    If IsError(Application.Match(.Cells(i, "B").Value2, Worksheets("week1").Columns("B"), 0)) Then

    NextRow = NextRow + 1
    .Rows(i).Copy Worksheets("uniques").Cells(NextRow, "A")
    End If
    Next i
    End With

    With Application

    .ScreenUpdating = True
    .Calculation = xlCalculationAutomatic
    End With
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  9. #9
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    This should be even quicker

    [vba]

    Sub IDENTIFY_duplicates()
    Dim i As Long
    Dim LastRow As Long
    Dim rng As Range

    With Application

    .ScreenUpdating = False
    .Calculation = xlCalculationManual
    End With

    With Worksheets("week2")

    LastRow = .Cells(.Rows.Count, "B").End(xlUp).Row
    .Columns("C").Insert
    .Range("C1") = "temp"
    .Range("C2").Resize(LastRow - 1).Formula = "=ISNUMBER(MATCH(B2,week1!B:B,0))"
    Set rng = .Range("C1").Resize(LastRow)
    rng.AutoFilter field:=1, Criteria1:="FALSE"
    On Error Resume Next
    Set rng = rng.SpecialCells(xlCellTypeVisible)
    On Error GoTo 0
    If Not rng Is Nothing Then

    rng.EntireRow.Copy Worksheets("uniques").Range("A1")
    End If
    .Columns("C").Delete
    End With

    With Application

    .ScreenUpdating = True
    .Calculation = xlCalculationAutomatic
    End With
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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