无法使用devise器和inputVBA代码

有人可以帮我把我的用户表单从cal工作表中提交到这个表中吗?

Private Sub cmdbutton_submitform_Click() Dim emptyRow As Long 'Make Sheet2 active Sheet2.Activate 'Determine emptyRow emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1 'Transfer information Cells(emptyRow, 1).Value = txtbox_number.Value Cells(emptyRow, 2).Value = txtbox_rank.Value Cells(emptyRow, 3).Value = txtbox_Name.Value Cells(emptyRow, 4).Value = txtbox_height.Value Cells(emptyRow, 5).Value = txtbox_weight.Value Cells(emptyRow, 6).Value = txtbox_right_rm.Value Cells(emptyRow, 7).Value = txtbox_left_rm.Value End Sub 

VBA_code提交

table_i_want_to_load_info

我认为你对表单代号和表名称感到困惑(见这个 )。 尝试

 Private Sub cmdbutton_submitform_Click() Dim emptyRow As Long With Worksheets("Sheet2") 'Determine emptyRow emptyRow = WorksheetFunction.CountA(.Range("A:A")) + 1 'Transfer information .Cells(emptyRow, 1).Value = txtbox_number.Value .Cells(emptyRow, 2).Value = txtbox_rank.Value .Cells(emptyRow, 3).Value = txtbox_Name.Value .Cells(emptyRow, 4).Value = txtbox_height.Value .Cells(emptyRow, 5).Value = txtbox_weight.Value .Cells(emptyRow, 6).Value = txtbox_right_rm.Value .Cells(emptyRow, 7).Value = txtbox_left_rm.Value End With End Sub 

使用Worksheet.Activate方法可能会失去正确从用户窗体中获取文本框数据所需的父窗体引用。 在这个Private Sub您应该能够通过其工作表.CodeName属性来引用Sheet2 ,并使用Me来引用用户窗体作为文本框的父窗体。

 Private Sub cmdbutton_submitform_Click() Dim emptyRow As Long 'Reference Sheet2 by CodeName as the parent worksheet of the .Cells With Sheet2 'Determine emptyRow emptyRow = .Cells(Rows.Count, 1).End(xlUp).Row + 1 'Transfer information .Cells(emptyRow, 1).Value = Me.txtbox_number.Value .Cells(emptyRow, 2).Value = Me.txtbox_rank.Value .Cells(emptyRow, 3).Value = Me.txtbox_Name.Value .Cells(emptyRow, 4).Value = Me.txtbox_height.Value .Cells(emptyRow, 5).Value = Me.txtbox_weight.Value .Cells(emptyRow, 6).Value = Me.txtbox_right_rm.Value .Cells(emptyRow, 7).Value = Me.txtbox_left_rm.Value End With End Sub 

我发现有点奇怪的是,您使用Worksheet .CodeName属性而不是Worksheet .Name属性来标识工作表。 我已经包含了一些链接,以确保您正确使用命名约定。 无论如何,我已经使用With … End With语句来避免重复识别父工作表。