[英](VBA) I am looking to automate the update of my inventory form when I activate a Macro to add the count from one sheet to another
I am working on an Inventory workbook that has the inventory in one sheet and another sheet where I can scan barcode into and activate a macro to update the inventory sheet.我正在处理一个库存工作簿,该工作簿在一张表和另一张表中有库存,我可以在其中扫描条形码并激活宏以更新库存表。
The goal is to read each cell in a column that has a value and then find the matching value in the other sheet and update the count by using the sum of the corresponding count values.目标是读取列中具有值的每个单元格,然后在另一张表中找到匹配值,并使用相应计数值的总和来更新计数。
The VBA code I have so far updates the first item on the list, but just continues to update it endlessly.到目前为止,我的 VBA 代码更新了列表中的第一项,但只是继续无休止地更新它。 I am not sure what the best approach is and looking for a better route to update it in an efficient manner.
我不确定最好的方法是什么,并且正在寻找一种更好的方法来有效地更新它。
This is what I have so far这是我到目前为止所拥有的
`Sub Inventory_Update() `子库存更新()
Dim i As Integer
Dim b As Integer
i = 2
Do While Cells(i, "D").Value <> ""
If Cells(i, "D").Value <> "" Then
b = 1
Do While b < 346
If Sheet1.Cells(b, "B").Value = Cells(i, "D").Value Then
Sheet1.Cells(b, "C").Value = Sheet1.Cells(b, "C").Value + Cells(i, "F").Value
Else
b = b + 1
Loop
i = i + 1
End If
Loop
End Sub结束子
` `
Like this - a For Next loop is better for b
像这样 - For Next 循环更适合
b
Sub Inventory_Update()
Dim i As Long, b As Long, wsInv As Worksheet, wsEntry As Worksheet
Set wsEntry = ThisWorkbook.Worksheets("Entry") 'for example
Set wsInv = ThisWorkbook.Worksheets("Inventory") 'or Sheet1
i = 2
'use a worksheet reference whenver you reference a range
Do While Len(wsEntry.Cells(i, "D").Value) > 0
For b = 1 To 346
If wsInv.Cells(b, "B") = wsEntry.Cells(i, "D").Value Then
With wsInv.Cells(b, "C")
.Value = .Value + wsEntry.Cells(i, "F").Value
End With
End If
Next b
i = i + 1
Loop
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.