[TABLE="class: outer_border, width: 50, align: left"]
<tbody>[TR]
[TD]OrderNo
[/TD]
[TD]Account
[/TD]
[TD]Name
[/TD]
[TD]Code
[/TD]
[TD]Description
[/TD]
[TD]Quantity
[/TD]
[/TR]
[TR]
[TD]1
[/TD]
[TD]22
[/TD]
[TD]Ex1
[/TD]
[TD]APPLE1
[/TD]
[TD]Apples
[/TD]
[TD]17
[/TD]
[/TR]
[TR]
[TD]2
[/TD]
[TD]38
[/TD]
[TD]Ex7
[/TD]
[TD]PEAR1
[/TD]
[TD]Pears
[/TD]
[TD]56
[/TD]
[/TR]
[TR]
[TD]3
[/TD]
[TD]41
[/TD]
[TD]Ex2
[/TD]
[TD]ORANG1
[/TD]
[TD]Oranges
[/TD]
[TD]180
[/TD]
[/TR]
[TR]
[TD]4
[/TD]
[TD]52
[/TD]
[TD]Ex8
[/TD]
[TD]LEMON1
[/TD]
[TD]Lemons
[/TD]
[TD]100
[/TD]
[/TR]
[TR]
[TD]5
[/TD]
[TD]38
[/TD]
[TD]Ex7
[/TD]
[TD]PEAR1
[/TD]
[TD]Pears
[/TD]
[TD]250
[/TD]
[/TR]
[TR]
[TD]6
[/TD]
[TD]22
[/TD]
[TD]Ex1
[/TD]
[TD]APPLE1
[/TD]
[TD]Apples
[/TD]
[TD]250
[/TD]
[/TR]
</tbody>[/TABLE]
[TABLE="class: outer_border, width: 50"]
<tbody>[TR]
[TD]Invoice
[/TD]
[TD]Account
[/TD]
[TD]Name
[/TD]
[TD]Code
[/TD]
[TD]Description
[/TD]
[TD]Quantity
[/TD]
[/TR]
[TR]
[TD]1
[/TD]
[TD]T1
[/TD]
[TD]Tom
[/TD]
[TD]ORANG1
[/TD]
[TD]Oranges
[/TD]
[TD]25
[/TD]
[/TR]
[TR]
[TD]2
[/TD]
[TD]S1
[/TD]
[TD]Simon
[/TD]
[TD]APPLE1
[/TD]
[TD]Apples
[/TD]
[TD]25
[/TD]
[/TR]
[TR]
[TD]3
[/TD]
[TD]S2
[/TD]
[TD]Sally
[/TD]
[TD]PEAR1
[/TD]
[TD]Pears
[/TD]
[TD]50
[/TD]
[/TR]
[TR]
[TD]4
[/TD]
[TD]D1
[/TD]
[TD]Dot
[/TD]
[TD]LEMON1
[/TD]
[TD]Lemons
[/TD]
[TD]10
[/TD]
[/TR]
[TR]
[TD]5
[/TD]
[TD]K1
[/TD]
[TD]Keith
[/TD]
[TD]APPLE1
[/TD]
[TD]Apples
[/TD]
[TD]50
[/TD]
[/TR]
[TR]
[TD]6
[/TD]
[TD]G1
[/TD]
[TD]Gary
[/TD]
[TD]PEAR1
[/TD]
[TD]Pears
[/TD]
[TD]25
[/TD]
[/TR]
</tbody>[/TABLE]
Hi, I need a little assistance. I have two tables on separate worksheets. Table 1 is purchases (Worksheet("Purchases")) & Table 2 is sales (Worksheet("Sales").
This code deducts the quantity of stock from the purchase when it's sold. But what I need is:- If the quantity of a sale is greater than the quantity in the purchase then it deducts the remaining quantity from the next purchase with that code.
Can anyone help me with this?
Thanks In Advance
<tbody>[TR]
[TD]OrderNo
[/TD]
[TD]Account
[/TD]
[TD]Name
[/TD]
[TD]Code
[/TD]
[TD]Description
[/TD]
[TD]Quantity
[/TD]
[/TR]
[TR]
[TD]1
[/TD]
[TD]22
[/TD]
[TD]Ex1
[/TD]
[TD]APPLE1
[/TD]
[TD]Apples
[/TD]
[TD]17
[/TD]
[/TR]
[TR]
[TD]2
[/TD]
[TD]38
[/TD]
[TD]Ex7
[/TD]
[TD]PEAR1
[/TD]
[TD]Pears
[/TD]
[TD]56
[/TD]
[/TR]
[TR]
[TD]3
[/TD]
[TD]41
[/TD]
[TD]Ex2
[/TD]
[TD]ORANG1
[/TD]
[TD]Oranges
[/TD]
[TD]180
[/TD]
[/TR]
[TR]
[TD]4
[/TD]
[TD]52
[/TD]
[TD]Ex8
[/TD]
[TD]LEMON1
[/TD]
[TD]Lemons
[/TD]
[TD]100
[/TD]
[/TR]
[TR]
[TD]5
[/TD]
[TD]38
[/TD]
[TD]Ex7
[/TD]
[TD]PEAR1
[/TD]
[TD]Pears
[/TD]
[TD]250
[/TD]
[/TR]
[TR]
[TD]6
[/TD]
[TD]22
[/TD]
[TD]Ex1
[/TD]
[TD]APPLE1
[/TD]
[TD]Apples
[/TD]
[TD]250
[/TD]
[/TR]
</tbody>[/TABLE]
[TABLE="class: outer_border, width: 50"]
<tbody>[TR]
[TD]Invoice
[/TD]
[TD]Account
[/TD]
[TD]Name
[/TD]
[TD]Code
[/TD]
[TD]Description
[/TD]
[TD]Quantity
[/TD]
[/TR]
[TR]
[TD]1
[/TD]
[TD]T1
[/TD]
[TD]Tom
[/TD]
[TD]ORANG1
[/TD]
[TD]Oranges
[/TD]
[TD]25
[/TD]
[/TR]
[TR]
[TD]2
[/TD]
[TD]S1
[/TD]
[TD]Simon
[/TD]
[TD]APPLE1
[/TD]
[TD]Apples
[/TD]
[TD]25
[/TD]
[/TR]
[TR]
[TD]3
[/TD]
[TD]S2
[/TD]
[TD]Sally
[/TD]
[TD]PEAR1
[/TD]
[TD]Pears
[/TD]
[TD]50
[/TD]
[/TR]
[TR]
[TD]4
[/TD]
[TD]D1
[/TD]
[TD]Dot
[/TD]
[TD]LEMON1
[/TD]
[TD]Lemons
[/TD]
[TD]10
[/TD]
[/TR]
[TR]
[TD]5
[/TD]
[TD]K1
[/TD]
[TD]Keith
[/TD]
[TD]APPLE1
[/TD]
[TD]Apples
[/TD]
[TD]50
[/TD]
[/TR]
[TR]
[TD]6
[/TD]
[TD]G1
[/TD]
[TD]Gary
[/TD]
[TD]PEAR1
[/TD]
[TD]Pears
[/TD]
[TD]25
[/TD]
[/TR]
</tbody>[/TABLE]
Hi, I need a little assistance. I have two tables on separate worksheets. Table 1 is purchases (Worksheet("Purchases")) & Table 2 is sales (Worksheet("Sales").
Code:
Sub Match1()
Dim rCl As Range
Dim Rw As Long
Dim Amt As Long
Dim sFind As String
Dim ws As Worksheet
Set ws = Worksheets("Purchases")
With Range("Sales") 'THIS IS THE NAMED RANGE OF THE SALES TABLE
For Rw = 1 To .Rows.Count
sFind = .Cells(Rw, 4).Text 'FINDS THE PRODUCT CODE
Amt = .Cells(Rw, 6).Value
On Error Resume Next
With ws.UsedRange.Columns(4)
Set rCl = .Find(sFind, LookIn:=xlValues, lookat:=xlWhole)
If Not rCl Is Nothing Then rCl.Offset(0, 2).Value = rCl.offset(0, 2).value - Amt
End With
Next Rw
End With
End Sub
This code deducts the quantity of stock from the purchase when it's sold. But what I need is:- If the quantity of a sale is greater than the quantity in the purchase then it deducts the remaining quantity from the next purchase with that code.
Can anyone help me with this?
Thanks In Advance