[英]UserForm. How to create it and use data inserted in it by user in macro
I need to create a UserForm. 我需要创建一个用户窗体。 It would have 3 controls: 它将具有3个控件:
1)Label: 'Please denote year' 1)标签:“请表示年份”
2)TextBox: ' Here user would insert the year ' 2)TextBox:“ 此处用户将插入年份 ”
3)CommandButton: ' After clicking it the year would be submitted ' 3)CommandButton:“ 单击后将提交年份 ”
The year inserted by user would be used in my macro, here is a piece of code with place where the inserted year should be used marked with a comment: 用户插入的年份将在我的宏中使用,下面是一段代码,其中应使用插入的年份标记有注释:
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
Moreover I would like to ask how to make my macro start to work after clicking the CommandButton in the UserForm. 此外,我想问一下在用户窗体中单击CommandButton后如何使宏开始工作。
Many thanks in advance, 提前谢谢了,
with best regards, 最诚挚的问候,
Artur Rutkowski 阿图尔·鲁特科夫斯基(Artur Rutkowski)
If you are asking how to run the macro when you click the command button, you simply place the macro inside the command button inside the userform. 如果您在单击命令按钮时询问如何运行宏,只需将宏放在用户窗体内的命令按钮内。
You can double click your command button, in the editor, and paste in your code: 您可以在编辑器中双击命令按钮,然后粘贴代码:
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
There are options in the right combobox for click, Dblclick, Enter, Exit, so on... 右侧组合框中有单击,Dblclick,Enter,退出等选项,依此类推...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.