简体   繁体   English

(VBA)我希望在激活宏以将计数从一张纸添加到另一张纸时自动更新我的库存表格

[英](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.

相关问题 激活另一张纸时出现VBA错误 - VBA Error when I activate another sheet 库存宏-将信息从一页纸复制到另一页 - Inventory Macro - copying information from one row of sheet to another sheet 我正在编写 vba 代码以一次从一张纸复制一行数据并粘贴到另一张纸中 - I am writing vba code to copy one row of data at a time from one sheet and pasting into another sheet 如何使用宏/vba 将值从一张纸粘贴到另一张纸上? - How can I paste the value from one sheet to another using macro/vba? 我在使VBA宏在一张纸上运行以选择另一张纸上的范围时遇到问题 - I have been having problems with getting a VBA macro running on one sheet to select a range on another sheet VBA Excel如何从工作表1激活工作表2、3和4的宏 - VBA Excel how to activate macro for sheet 2, 3 and 4 from sheet 1 我正在尝试使用vba将选择从一个工作表复制到另一个工作表并设置新工作表的样式,但是一组列值未复制 - I am trying to copy a selection from one worksheet to another using vba and style the new sheet but one set of column values is not copying over Excel 将内容从一张纸复制到另一张纸,无需 VBA/宏 - Excel copy contents from one sheet to another without VBA/Macro 从一张纸到另一张纸的VBA宏读/写速度慢 - Slow VBA macro reading/writing from one sheet to another Excel-将单元格+宏+ VBA从一张纸复制到另一张纸? - Excel - copy cells+macro+VBA from one sheet to another?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM