gpt4 book ai didi

excel - 库存宏 - 结合步骤和while循环?

转载 作者:行者123 更新时间:2023-12-04 22:29:26 26 4
gpt4 key购买 nike

我正在开发一个库存控制宏,我在其中扫描代码、区域、团队和条形码,以了解该项目是被扫描进还是出。现在我为这些功能中的每一个使用了 4 个不同的按钮(1. 产品 2. 团队 3. 区域 4. 输入/输出)。我希望有人可以帮助改进这一点,因此只需按下一个按钮,您只需将所有 4 个按钮连续扫描到弹出框即可。我还试图弄清楚如何创建一个 while 循环,以便一旦扫描了一个产品的所有 4 个类别,它就会自动跳到下一行以开始扫描新产品。我假设这需要一个 do while 循环,但我正在努力实现这一点,因为我还没有自动执行所有 4 个步骤。

我曾尝试运行 do while 代码,但我正在努力让它工作,但我首先在努力弄清楚如何让四个步骤在前一个步骤之后自动弹出。

Sub ScanProductBarcode_Click()

Dim Barcode
Dim ProductGroup

Barcode = InputBox("Please scan a PRODUCT barcode and hit enter if you need to")
ThisWorkbook.Sheets("Sheet2").Range("A2") = Barcode
ThisWorkbook.Sheets("Sheet2").Range("A2").Offset(0, 5) = Now 'Cell Formatted for Date
ThisWorkbook.Sheets("Sheet2").Range("A2").Offset(0, 6) = Now 'Cell Formatted for Time

End Sub

Sub ScanTeamBarcode_Click()

Dim Team

Team = InputBox("Please scan the TEAM barcode and hit enter if you need to")
ThisWorkbook.Sheets("Sheet2").Range("H2") = Team

End Sub


Sub ScanRegionBarcode_Click()

Dim Region

Region = InputBox("Please scan the REGION barcode and hit enter if you need to")
ThisWorkbook.Sheets("Sheet2").Range("J2") = Region

End Sub

Sub ScanInOut_Click()

Dim InOut

InOut = InputBox("Please scan the device IN or OUT barcode and hit enter if you need to")
ThisWorkbook.Sheets("Sheet2").Range("L2") = InOut

End Sub

希望有人可以帮助我只需单击一个按钮即可运行所有这四个扫描步骤,然后在放到 Excel 的下一行开始扫描下一个产品后。
提前致谢!

最佳答案

循环扫描所有条码:

Sub ScanAllBarcodes_Click()

Dim Barcode, Team, Region, InOut
Dim ProductGroup, rw As Range

Do

Barcode = GetBC("PRODUCT")
If Len(Barcode) = 0 Then Exit Do '<<< empty input terminates loop

Team = GetBC("TEAM")
Region = GetBC("REGION")
InOut = GetBC("device IN or OUT")

Set rw = ThisWorkbook.Sheets("Sheet2").Cells(Rows.Count, 1).End(xlUp).Offset(1).EntireRow
'make sure the row is really empty (in case of missing "A" value)
Do While Application.CountA(rw) > 0
Set rw = rw.Offset(1, 0)
Loop

With rw
.Cells(1) = Barcode
.Cells(6) = Now
.Cells(7) = Now
.Cells(8) = Team
.Cells(10) = Region
.Cells(12) = InOut
End With

Loop

End Sub

Function GetBC(nm)
GetBC = InputBox("Please scan a " & nm & " barcode and hit enter if you need to")
End Function

关于excel - 库存宏 - 结合步骤和while循环?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54498867/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com