let's say here is my sample workbook ("productmovement")
[TABLE="width: 300"]
<tbody>[TR]
[TD]Product
[/TD]
[TD]Out
[/TD]
[TD]Stock
[/TD]
[TD]Total
[/TD]
[/TR]
[TR]
[TD]apple
[/TD]
[TD]5
[/TD]
[TD]8
[/TD]
[TD]3
[/TD]
[/TR]
[TR]
[TD]banana
[/TD]
[TD]4
[/TD]
[TD]9
[/TD]
[TD]5
[/TD]
[/TR]
[TR]
[TD]orange
[/TD]
[TD]3
[/TD]
[TD]10
[/TD]
[TD]7
[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
and here is my samlple workbook ("productinventory")
[TABLE="width: 300"]
<tbody>[TR]
[TD]Product
[/TD]
[TD]Stock
[/TD]
[TD]date
[/TD]
[/TR]
[TR]
[TD]grapes
[/TD]
[TD]10
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]apple
[/TD]
[TD]8
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]orange
[/TD]
[TD]10
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]avocado
[/TD]
[TD]5
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]orange
[/TD]
[TD]10
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]banana
[/TD]
[TD]9
[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
How can I update the remaining stock of fruits on workbook ("productinventory") based on the Total on my workbook ("productmovement")?
sorry im just a newbie in VBA
here is my current code
Private Sub CommandButton1_Click()
Dim lastrow, cell As Long
Dim a, b As Integer
a = 1
lastrow = Sheets("Sheet2").Cells(Rows.Count, 1).End(xlUp).Row
Do While Cells(a, 1).Value <> ""
Cells(a, 1).Value
b = Cells(a, 1).Offset(0, 1).Value
Workbooks("productinventory").Sheets("Sheet1").Range("A2:A" & lastrow).Find(What:=Cells(a, 1).Value, LookIn:=xlValues, LookAt:=xlWhole).Activate
' error here "run time error 438"
cell = ActiveCell.Row
Cells(sonsat, 2) = b
a = a + 1
Loop
End Sub
[TABLE="width: 300"]
<tbody>[TR]
[TD]Product
[/TD]
[TD]Out
[/TD]
[TD]Stock
[/TD]
[TD]Total
[/TD]
[/TR]
[TR]
[TD]apple
[/TD]
[TD]5
[/TD]
[TD]8
[/TD]
[TD]3
[/TD]
[/TR]
[TR]
[TD]banana
[/TD]
[TD]4
[/TD]
[TD]9
[/TD]
[TD]5
[/TD]
[/TR]
[TR]
[TD]orange
[/TD]
[TD]3
[/TD]
[TD]10
[/TD]
[TD]7
[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
and here is my samlple workbook ("productinventory")
[TABLE="width: 300"]
<tbody>[TR]
[TD]Product
[/TD]
[TD]Stock
[/TD]
[TD]date
[/TD]
[/TR]
[TR]
[TD]grapes
[/TD]
[TD]10
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]apple
[/TD]
[TD]8
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]orange
[/TD]
[TD]10
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]avocado
[/TD]
[TD]5
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]orange
[/TD]
[TD]10
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]banana
[/TD]
[TD]9
[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
How can I update the remaining stock of fruits on workbook ("productinventory") based on the Total on my workbook ("productmovement")?
sorry im just a newbie in VBA
here is my current code
Private Sub CommandButton1_Click()
Dim lastrow, cell As Long
Dim a, b As Integer
a = 1
lastrow = Sheets("Sheet2").Cells(Rows.Count, 1).End(xlUp).Row
Do While Cells(a, 1).Value <> ""
Cells(a, 1).Value
b = Cells(a, 1).Offset(0, 1).Value
Workbooks("productinventory").Sheets("Sheet1").Range("A2:A" & lastrow).Find(What:=Cells(a, 1).Value, LookIn:=xlValues, LookAt:=xlWhole).Activate
' error here "run time error 438"
cell = ActiveCell.Row
Cells(sonsat, 2) = b
a = a + 1
Loop
End Sub