簡體   English   中英

VB代碼:將用戶窗體數據導入Excel工作表

[英]VB code : Import userform data to excel sheet

我希望填充一個vb代碼,該代碼可以讓我執行以下功能:

以下是我的用戶表單:

條件1: 在此處輸入圖片說明

單擊添加庫存按鈕后,它將上傳我填寫在數據表中的數據,名為庫存(A4:A6)

一旦產品和現場庫存被填滿,紅色將自動生成。

對於可用庫存,將可以在庫存中的整個數據表中進行搜索,以匯總正在添加的所有庫存或最后可用庫存的數量。

如果“庫存”表中不包含產品(新產品),它將在用戶窗體的“可用庫存”字段中自動顯示0或空白。

條件2: 在此處輸入圖片說明

單擊添加庫存按鈕后,它將上傳我填寫在數據表中的數據,名為庫存(A7)

提交后,單擊“添加庫存”按鈕,庫存表應如下所示: 在此處輸入圖片說明

我不知道如何將數據導入到我的庫存表的這種方法。

謝謝或高級幫助

我的代碼將如下所示:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM