简体   繁体   English

用户表格。 如何创建它并使用用户在宏中插入的数据

[英]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.

相关问题 Excel VBA用户表单。 将数据添加到标题下方的新行中 - Excel VBA userform. Add data into a new row, below headers 如何使用来自word上的用户表单的输入数据,以便稍后插入到我的编码将打开的excel文件中 - How can I use input data from a userform on word to be later inserted into a excel file that my coding will open VBA Excel 用户窗体。 如何判断哪张图片被点击 - VBA Excel UserForm. How to determine which image has been clicked 如何使用在主模块中输入到用户窗体中的数据 - How to use data entered into userform in main module 如何使用用户窗体文本框和宏在工作簿单元中创建到硬盘文件的超链接 - How to Create Hyperlink in Workbook Cell to Hard Drive File using a Userform Textbox and Macro 如果用户插入了新的工作表,则自动运行宏 - Automatically run macro if the user inserted a new worksheet 如何创建一个宏,它将在不打开工作簿的情况下从外接程序打开用户窗体 - How to create a macro that will open a userform from an Add-in without opening the workbook 如何在用户窗体中将ComboBox的值传递给宏 - How to pass value of ComboBox in userform to macro 如何从宏运行用户窗体? - How can I run a userform from a macro? 如何执行与用户窗体中的复选框关联的宏 - How to execute macro associated with a check box in a UserForm
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM