compare two sheets, with VBA

auto

Board Regular
Joined
May 20, 2012
Messages
53
hi, i am having two sheets in my excel, first sheet named sales, the other one named sent,
in sheet sales i have all my data, column "B" is the Sku, and column "H" is qty.
in sheet sent, there is a report what i get every morning from Qty that got changed, So i have there in column "A" the Sku, and column "D" is the new Qty,
now i need that my sheet sales should get updated automatically from sheet sent.
i tried already alot of ways, spending weeks without success, maybe someone can help me out here, i will give some ways what i tried and where i get stuck.
Code:
Sub MyIfCode()

Dim I As Range
Dim r As Range

Dim MyUpdate As Range
Dim OldList As Range

Dim Sales As Object
Dim Sent As Object

Set Sales = Worksheets("Sales")
Set Sent = Worksheets("Sent")


Set MyUpdate = Sent.Range("A:A").UsedRange
Set OldList = Sales.Range("B:B").UsedRange



For Each I In MyUpdate
   For Each r In OldList
        If I = r Then
           r.Offset(0, 6) = I.Offset(0, 3)
        End If

     Next r

Next I

End Sub
in the above code, it get stuck here> Set MyUpdate = Sent.Range("A:A").UsedRange
Set OldList = Sales.Range("B:B").UsedRange

here is another code i tried, actuelly with the help of a mrexcel thread
http://www.mrexcel.com/forum/excel-questions/9419-compare-list-b-add-records-b-not.html

here is my code,
Code:
Sub test()
Dim Rng1 As Range, Rng2 As Range, C As Range
Dim Z

With Sheets("Sent")
    .UsedRange
    Set Rng2 = Intersect(.UsedRange, .Range("A:A"))
    For Each C In Rng2
        With Sheets("Sales")
        .UsedRange
            Set Rng1 = Intersect(.UsedRange, .Range("B:B"))
            Z = Application.Match(C, Rng1, 0)
            If C = Rng1 Then
            
               
            Rng1.Offset(0, 6) = C.Offset(0, 3)
            
            
            End If
        End With
    Next C
End With
MsgBox "Done!"

End Sub
by this code i get stuck here> If C = Rng1 Then "error Type Mismatch"

can anyone help me out?
i am really sick of working on that for weeks.
 

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