Consulting

Results 1 to 5 of 5

Thread: Comparing spreadsheet - VBA almost working..

  1. #1

    Comparing spreadsheet - VBA almost working..

    Hi,

    I am using a code to compare two spreadsheet.
    One of the function is to copy the modified records in a different worksheet, highlighting changes element in red.
    The script works, but ONLY when the cell is modified to "blank"(no value), I get coloured in red the upper cell instead of the correct one.

    Here the script, any help?

    Sub GDV()
        Dim WsA As Worksheet, WsB As Worksheet, WsC As Worksheet, WsD As Worksheet, WsE As Worksheet
        Dim rFind As Range, c As Range
        Dim I As Integer, ColCnt As Integer
         
        Set WsA = Worksheets("OldExport")
        Set WsB = Worksheets("NewExport")
        Set WsC = Worksheets("Changes")
        Set WsD = Worksheets("PosDeleted")
        Set WsE = Worksheets("PosAdded")
         
        ColCnt = WsA.Cells(1, Columns.Count).End(xlToLeft).Column
         
        With CreateObject("Scripting.Dictionary")
            For Each c In WsA.Range("A2", WsA.Range("A" & Rows.Count).End(xlUp))
                If Not .exists(c.Value) Then
                    .Add c.Value, False
                    Set rFind = WsB.Columns(1).Find(What:=c.Value, LookIn:=xlValues)
                    If Not rFind Is Nothing Then
                        For I = 1 To ColCnt
                            If Not c.Offset(, I - 1) = WsB.Cells(rFind.Row, I) Then
                                If .Item(c.Value) = False Then
                                    rFind.Resize(1, ColCnt).Copy WsC.Range("A" & Rows.Count).End(xlUp).Offset(1)
                                    .Item(c.Value) = True
                                End If
                                WsC.Cells(Rows.Count, I).End(xlUp).Interior.ColorIndex = 3
                            End If
                        Next I
                    Else
                        MsgBox c.Value & " PosID has been canceled!"
                        c.Resize(1, ColCnt).Copy WsD.Range("A" & Rows.Count).End(xlUp).Offset(1)
                    End If
                End If
            Next c
            For Each c In WsB.Range("A2", WsB.Range("A" & Rows.Count).End(xlUp))
                If Not .exists(c.Value) Then
                    MsgBox c.Value & " PosID has been added!"
                    c.Resize(1, ColCnt).Copy WsE.Range("A" & Rows.Count).End(xlUp).Offset(1)
                End If
            Next c
        End With
    End Sub

  2. #2
    VBAX Regular
    Joined
    Feb 2012
    Posts
    31
    Location
    ------------------------------------------------

    Thanks For All Your Help

    Windows 7

    Excel 2010

    Any codes I provide please try on a copy of your workbook first as these cannot be undone!

    To get the most precise answer, it is best to upload/attach a sample workbook (sensitive data scrubbed/removed/changed) that contains an example of your raw data on one worksheet, and on another worksheet your desired results.

    The structure and data types of the sample workbook must exactly duplicate the real workbook. Include a clear and explicit explanation of your requirements.

  3. #3
    I am sorry, I am trying to solve the issue and I am looking for help around.

  4. #4
    VBAX Regular
    Joined
    Feb 2012
    Posts
    31
    Location
    Quote Originally Posted by cerebrolele
    I am sorry, I am trying to solve the issue and I am looking for help around.
    The problem with multi posting is you get several people working on giving you the answer on all different websites. Not etiquette!

    Cross posting without providing a link to the other thread is a violation of the Forum Rules. We prefer you do not cross post, but when doing so you are obligated to provide the link per your agreement to abide the rules of this forum. (All Excel forums have a similar rule about cross posting.)
    ------------------------------------------------

    Thanks For All Your Help

    Windows 7

    Excel 2010

    Any codes I provide please try on a copy of your workbook first as these cannot be undone!

    To get the most precise answer, it is best to upload/attach a sample workbook (sensitive data scrubbed/removed/changed) that contains an example of your raw data on one worksheet, and on another worksheet your desired results.

    The structure and data types of the sample workbook must exactly duplicate the real workbook. Include a clear and explicit explanation of your requirements.

  5. #5
    to who may be interested
    I found a solution (workaround) here:
    h**p://w*w.excelforum.com/excel-programming/836871-vba-comparison-spreadsheet.html?p=2818323&viewfull=1#post2818323

    (cannot post links)

Posting Permissions

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