Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何:Excel VBA命令按钮将用户表单值输入到当前行?_Excel_Vba - Fatal编程技术网

如何:Excel VBA命令按钮将用户表单值输入到当前行?

如何:Excel VBA命令按钮将用户表单值输入到当前行?,excel,vba,Excel,Vba,我目前有一个UserForm“UserForm1”,它从组合框中获取值(课程、讲师、开始时间等),并将它们保存到指定的表“讲师小时”。命令按钮“保存”将所选值保存在“InstructorHours”表的下一行中。我遇到的问题是让CommandButton将相同的信息保存到另一个工作表“日历”上当前选定的行中。理想情况下,我希望在“日历”工作表上的一行内单击,并将来自用户的值输入到我选择的行中 Private子命令按钮1\u单击() '将输入值复制到工作表。 暗淡的光线和长的一样 '下一个可用行

我目前有一个UserForm“UserForm1”,它从组合框中获取值(课程、讲师、开始时间等),并将它们保存到指定的表“讲师小时”。命令按钮“保存”将所选值保存在“InstructorHours”表的下一行中。我遇到的问题是让CommandButton将相同的信息保存到另一个工作表“日历”上当前选定的行中。理想情况下,我希望在“日历”工作表上的一行内单击,并将来自用户的值输入到我选择的行中

Private子命令按钮1\u单击()
'将输入值复制到工作表。
暗淡的光线和长的一样
'下一个可用行
将ws设置为工作表
设置ws=工作表(“讲师小时”)
lRow=ws.Cells(Rows.Count,1)。End(xlUp)。Offset(1,0)。Row
与ws
.Cells(lRow,1).Value=Me.ComboBox1.Value
.Cells(lRow,2).Value=Me.ComboBox2.Value
.Cells(lRow,3).Value=Me.ComboBox3.Value
.Cells(lRow,4).Value=Me.ComboBox4.Value
.Cells(lRow,5).Value=Me.ComboBox5.Value
.Cells(lRow,6).Value=Me.ComboBox6.Value
.Cells(lRow,7).Value=Me.TextBox1.Value
以
'清除输入控件。
Me.ComboBox1.Value=“”
Me.ComboBox2.Value=“”
Me.ComboBox3.Value=“”
Me.ComboBox4.Value=“”
Me.ComboBox5.Value=“”
Me.ComboBox6.Value=“”

End Sub
一般来说,如果您想处理某个活动,您可能需要一些“活动”的内容(例如ActiveSheet或ActiveCell)用于活动选择活动

我建议为以下内容使用另一个命令按钮(在我的头顶上写下这个,我还没有验证代码):


这至少应该提供一个起点。

但您正在定义
Set ws=Worksheets(“讲师小时”)
。您提到它必须是
Calendar
,然后您可以只做
lrow=Selection.Row
您遇到了什么问题,以及您尝试解决了什么问题?在定义.cells的地方,您可以先尝试.Selection,然后您可以将行(1到6)从每个后续条目的选择中偏移(第2项至第7项的账户)。
Private Sub CommandButton2_Click()

'Input based on the selection
    ActiveCell.Value = Me.ComboBox1.Value
    ActiveCell.Offset(1,0).Value = Me.ComboBox2.Value
    ActiveCell.Offset(2,0).Value = Me.ComboBox3.Value
    ActiveCell.Offset(3,0).Value = Me.ComboBox4.Value
    ActiveCell.Offset(4,0).Value = Me.ComboBox5.Value
    ActiveCell.Offset(5,0).Value = Me.ComboBox6.Value
    ActiveCell.Offset(6,0).Value = Me.TextBox1.Value

'Clear input controls.
Me.ComboBox1.Value = ""
Me.ComboBox2.Value = ""
Me.ComboBox3.Value = ""
Me.ComboBox4.Value = ""
Me.ComboBox5.Value = ""
Me.ComboBox6.Value = ""

End Sub