problem on transferring data to another workbook

astral007

New Member
Joined
Oct 12, 2017
Messages
4
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
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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