运行时错误424对象必需(在数据input用户窗体中添加数据)

我是VBA新手,根本没有任何背景知识。 我只是看了YouTubevideo,并尝试学习。 我正在为装运摘要信息进行数据input。 但是,我运行我的用户窗体时遇到Runtime Error 464 。 我一遍又一遍地检查了我的代码,并找不到解决scheme。 在此先感谢那些愿意帮助的人!

 Private Sub CommandButton1_Click() Dim TextBox As String Dim Database As Worksheet Set Database = Worksheets("ShipData") eRow = ThisWorksheet.ShipData.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row ShipData.Cells(eRow, 1).Value = TextBox6.Text ShipData.Cells(eRow, 1).Value = ComboBox1.List ShipData.Cells(eRow, 2).Value = ComboBox2.List ShipData.Cells(eRow, 3).Value = TextBox1.Text ShipData.Cells(eRow, 4).Value = TextBox2.Text ShipData.Cells(eRow, 5).Value = TextBox3.Text ShipData.Cells(eRow, 6).Value = ComboBox3.List ShipData.Cells(eRow, 7).Value = TextBox4.Text ShipData.Cells(eRow, 8).Value = TextBox5.Text ShipData.Cells(eRow, 9).Value = ComboBox4.Text ShipData.Cells(eRow, 11).Value = TextBox7.Text ShipData.Cells(eRow, 12).Value = TextBox8.Text ShipData.Cells(eRow, 13).Value = TextBox9.Text ShipData.Cells(eRow, 14).Value = TextBox10.Text ShipData.Cells(eRow, 15).Value = TextBox11.Text ShipData.Cells(eRow, 16).Value = TextBox12.Text ShipData.Cells(eRow, 17).Value = TextBox13.Text ShipData.Cells(eRow, 18).Value = TextBox14.Text ShipData.Cells(eRow, 19).Value = TextBox15.Text ShipData.Cells(eRow, 20).Value = TextBox16.Text Unload Me ShipmentSummary.Show End Sub 

您已经使用Set Database = Worksheets("ShipData") Set您的"ShipData"工作表,因此您现在可以使用Database来引用它,而不是ThisWorksheet.ShipData

我相信这是你正在努力实现的:

 Private Sub CommandButton1_Click() Dim TextBox As String Dim Database As Worksheet Set Database = Worksheets("ShipData") With Database eRow = .Cells(.Rows.Count, 1).End(xlUp).Offset(1, 0).Row .Cells(eRow, 1).Value = TextBox6.Text .Cells(eRow, 1).Value = ComboBox1.List '<-- better use ComboBox1.Value .Cells(eRow, 2).Value = ComboBox2.List '<-- better use ComboBox2.Value .Cells(eRow, 3).Value = TextBox1.Text .Cells(eRow, 4).Value = TextBox2.Text .Cells(eRow, 5).Value = TextBox3.Text .Cells(eRow, 6).Value = ComboBox3.List '<-- better use ComboBox3.Value .Cells(eRow, 7).Value = TextBox4.Text .Cells(eRow, 8).Value = TextBox5.Text .Cells(eRow, 9).Value = ComboBox4.Text '<-- better use ComboBox4.Value .Cells(eRow, 11).Value = TextBox7.Text .Cells(eRow, 12).Value = TextBox8.Text .Cells(eRow, 13).Value = TextBox9.Text .Cells(eRow, 14).Value = TextBox10.Text .Cells(eRow, 15).Value = TextBox11.Text .Cells(eRow, 16).Value = TextBox12.Text .Cells(eRow, 17).Value = TextBox13.Text .Cells(eRow, 18).Value = TextBox14.Text .Cells(eRow, 19).Value = TextBox15.Text .Cells(eRow, 20).Value = TextBox16.Text End With Unload Me ShipmentSummary.Show End Sub