Compare Sheets

TiffanyG

Board Regular
Joined
Dec 17, 2006
Messages
74
I prepare quarterly reports and need to pick up any new accounts but also need to report accounts that were lost. Each account has a unique account number and all info about the account is in one row. For instance:

Sheet - 1Q
Branch Act # Name Rate Code
1 321 John Doe 6

Sheet - 2Q
1 321 Joh Doe 5

I want a VB Code that will compare 1Q and 2Q pick up this row and show it is now rated a 5 instead of 6 in a new sheet named consolidation. BUT if any accounts are new 2Q I need to pick them up OR if any have dropped off and are not on the 2Q I need pick them up.

Is this possible? I use VB but can only do simple procedures.
Any help is greatly appreciated!
 
Fazza,
I replied earlier but I didn't see it posted. If this is a duplictate, I am sorry but I am just so excited about this code!

You are the greatest! It works fantastic! Thank you so much for all your hlep.

You guys are the greatest!!

Thanks! 8-)
 
Upvote 0

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
How about?
Code:
Sub test()
Dim a, i As Long, ii As Integer, w(), dic As Object
Set dic = CreateObject("Scripting.Dictionary")
With Sheets("Sheet1") '<- alter to suite
    a = .Range("a1").CurrentRegion.Value
End With
For i = 1 To UBound(a,1)
    If Not dic.exists(a(i,1)) Then
        ReDim w(1 To UBound(a,2) + 1)
        For ii = 1 To UBound(a,2) : w(ii) = a(i,ii) : Next
        dic.add a(i,1), w
    End If
Next
With Sheets("Sheet2")
    a = .Range("a1").CurrentRegion.Value
End With
For i = 1 To UBound(a,1)
    If Not dic.exists(a(i,1)) Then
        ReDim w(1 To UBound(a,2) + 1)
        For ii = 1 To UBound(a,2) : w(ii) = a(i,ii) : Next
        w(UBound(w)) = "New" : dic.add a(i,1) , w
    Else
        w = dic(a(i,1))
        If w(UBound(w)) <> "New" Then
            If w(3) <> a(i,3) Then
                w(3) = a(i,3) : w(UBound(w)) = "Changed"
            Else
                w(UBound(w)) = "Remain"
            End If
        End If
        dic(a(i,1)) = w
    End If
Next
y = dic.items : Set dic = Nothing : Erase a
With Sheets("Consolidate").Range("a1")
    .CurrentRegion.ClearContents
    .EntireRow.Value = Sheets("Sheet1").Rows(1).Value ' Alter sheet name if needed
    .End(xlToRight).Offset(,1).Value = "Status"
    For i = 1 To UBound(y)
        .Offset(i).Resize(,UBound(y(i))).Value = y(i)
        If IsEmpty(y(i)(UBound(y(i)))) Then
            .Offset(i,UBound(y(i)(UBound(y(i)))-1).Value = "Droped"
        End If
    Next
End With
End Sub
 
Upvote 0
Get an error on the line

Code:
Next
y = dic.items: Set dic = Nothing: Erase a[code]

compile error
next without for[/code]
 
Upvote 0
OOps!

Missing an "End IF" after the line of
Code:
    Else
        UBound(UBound(w)) = "Remain"
    End If  '<- This one
End If
will fix previous code
 
Upvote 0
Get another compile error
for control variable already in use on this line

below the word 'status' at the bottom (this code is at the top also)

For i = 1 To UBound(y)
Code:
 
Upvote 0
Get another compile error
for control variable already in use on this line

below the word 'status' at the bottom (this code is at the top also)

For i = 1 To UBound(y)

I don't understand why you get such an error.

It doesn't make sense to me. "In use"

Can you copy the previous code and try again?
 
Upvote 0
jindon,

I am getting a syntax error here. If you don't want to look at it I can use Fazza's. It just drives me crazy trying to figure it out. As I said I am learning and trying to figure out what these errors mean. Only way to learn!



.Offset(i,UBound(y(i)(UBound(y(i)))-1).Value = "Droped"
Code:
Syntax error on this line.
 
Upvote 0
I've only looked over the post a few seconds, but try adding a comma.

Code:
 .Offset(i,UBound(y(i)(UBound(y(i)))-1).Value = "Droped"

to
Code:
 .Offset(i,UBound(y(i),(UBound(y(i)))-1).Value = "Droped"

??

UBound(y(i),(UBound(y(i)))-1 )

should be the number of collumns you want to offset by.
 
Upvote 0
Thanks for the response.

Now I am getting the error on that same line:

run time error '9'"
subscript out of range

the code really doesn't like that line..
 
Upvote 0

Forum statistics

Threads
1,223,275
Messages
6,171,122
Members
452,381
Latest member
Nova88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top