簡體   English   中英

用戶表格。 如何創建它並使用用戶在宏中插入的數據

[英]UserForm. How to create it and use data inserted in it by user in macro

我需要創建一個用戶窗體。 它將具有3個控件:
1)標簽:“請表示年份”
2)TextBox:“ 此處用戶將插入年份
3)CommandButton:“ 單擊后將提交年份

用戶插入的年份將在我的宏中使用,下面是一段代碼,其中應使用插入的年份標記有注釋:

            For i = startrow To endrow

            Range("A" & i, "C" & i).Copy
            Sheets("Sheet13").Range("B" & i + 1).PasteSpecial xlPasteAll
            Range("D" & i).Copy
            Sheets("Sheet13").Range("G" & i + 1).PasteSpecial xlPasteAll
            Range("H" & i).Copy
            Sheets("Sheet13").Range("H" & i + 1).PasteSpecial xlPasteAll
            Sheets("Sheet13").Range("E" & i + 1).Value = "Inventory"
            Sheets("Sheet13").Range("F" & i + 1).Value = "31/12/2013" 'Here should be used the inserted year. I don't want to set the value to "31/12/2013?" but to "31/12/'Inserted Year'"
            Sheets("Sheet13").Range("O" & i + 1).Value = "R"

            Next  

此外,我想問一下在用戶窗體中單擊CommandButton后如何使宏開始工作。

提前謝謝了,
最誠摯的問候,
阿圖爾·魯特科夫斯基(Artur Rutkowski)

如果您在單擊命令按鈕時詢問如何運行宏,只需將宏放在用戶窗體內的命令按鈕內。

您可以在編輯器中雙擊命令按鈕,然后粘貼代碼:

Private Sub CommandButton1_Click()
startrow = 1
endrow = 4
  For i = startrow To endrow
    Range("A" & i, "C" & i).Copy
    Sheets("Sheet13").Range("B" & i + 1).PasteSpecial xlPasteAll
    Range("D" & i).Copy
    Sheets("Sheet13").Range("G" & i + 1).PasteSpecial xlPasteAll
    Range("H" & i).Copy
    Sheets("Sheet13").Range("H" & i + 1).PasteSpecial xlPasteAll
    Sheets("Sheet13").Range("E" & i + 1).Value = "Inventory"
    Sheets("Sheet13").Range("F" & i + 1).Value = "31/12/2013" 'Here should be used the inserted year. I don't want to set the value to "31/12/2013?" but to "31/12/'Inserted Year'"
    Sheets("Sheet13").Range("O" & i + 1).Value = "R"

  Next
End Sub

右側組合框中有單擊,Dblclick,Enter,退出等選項,依此類推...

暫無
暫無

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

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