gpt4 book ai didi

vba - VB代码: Import userform data to excel sheet

转载 作者:行者123 更新时间:2023-12-04 21:02:32 24 4
gpt4 key购买 nike

我希望填充一个可以让我执行以下功能的 vb 代码:

以下是我的用户表单:

条件一:
enter image description here

单击添加库存按钮后,它将上传我填写的数据表,名为 Inventory (A4:A6)

一旦产品和现场库存被填充,红色将自动生成。

对于可用库存,将能够在 Inventory 中搜索整个数据表,以总结所有正在添加的库存或可用库存的最后数量。

如果内部库存表不包含产品(新产品),它将在用户表单中的可用库存字段中自动显示 0 或空白。

条件二:
enter image description here

单击添加库存按钮后,它将上传我填写的数据表,名为 Inventory (A7)

提交后单击“添加库存”按钮,库存表应如下所示:
enter image description here

我不知道这种方法如何将数据导入我的库存表。

感谢或高级帮助

我的代码将是这样的:

Private Sub Addstock_Click()

Dim lRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Inventory")
lRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1

With ws
.Cells(lRow, 1).Value = Me.ordernumber.Value
'.Cells(lRow, 2).Value = Me.TextBox5.Value
.Cells(lRow, 3).Value = Me.supplier.Value
.Cells(lRow, 4).Value = Me.productname.Value
.Cells(lRow, 5).Value = Me.stockavai.Value
.Cells(lRow, 6).Value = Me.qty.Value
.Cells(lRow, 7).Value = Me.newstock.Value
.Cells(lRow, 8).Value = Me.unit.Value
.Cells(lRow, 9).Value = Me.amount.Value
End With




End Sub

最佳答案

尝试这个:

Private Sub Addstock_Click()

Dim lRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Inventory")
lRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues)

With ws
.Cells(lRow.Row + 1, 1).Value = Me.ordernumber.Value
'.Cells(lRow.Row + 1, 2).Value = Me.TextBox5.Value
.Cells(lRow.Row + 1, 3).Value = Me.supplier.Value
.Cells(lRow.Row + 1, 4).Value = Me.productname.Value
.Cells(lRow.Row + 1, 5).Value = Me.stockavai.Value
.Cells(lRow.Row + 1, 6).Value = Me.qty.Value
.Cells(lRow.Row + 1, 7).Value = Me.newstock.Value
.Cells(lRow.Row + 1, 8).Value = Me.unit.Value
.Cells(lRow.Row + 1, 9).Value = Me.amount.Value
End With




End Sub

关于vba - VB代码: Import userform data to excel sheet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33386258/

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