【发布时间】:2019-08-13 05:08:47
【问题描述】:
我用 Excel 制作了一个用户窗体。它有文本框和复选框以及命令按钮。
UserForm 以 TextBoxes 开头,然后出现一些 CheckBoxes 和 TextBoxes 继续。 cmdAddData_click 用于将数据发送到工作表。我搜索了很多,但我是这里的新手。
当我想发送数据时它会给出
运行时错误、应用程序定义或对象定义错误。
感谢所有帮助。
Private Sub cmdAddData_Click()
lastrow = ThisWorkbook.Worksheets("00. Active Customers").Cells(Rows.Count, 1).End(xlUp).Row
ThisWorkbook.Worksheets("00. Active Customers").Cells(lastrow + 1, 0).Value = txtDate.Text
ThisWorkbook.Worksheets("00. Active Customers").Cells(lastrow + 1, 1).Value = txtName.Text
'after 34 textboxes, now for checkboxes
If cbxADSL.Value = True Then
ThisWorkbook.Worksheets("00. Active Customers").Cells(lastrow + 1, 35).Value = "Yes"
Else
ThisWorkbook.Worksheets("00. Active Customers").Cells(lastrow + 1, 35).Value = "No"
End If
If cbxAlarm.Value = True Then
ThisWorkbook.Worksheets("00. Active Customers").Cells(lastrow + 1, 36).Value = "Yes"
Else
ThisWorkbook.Worksheets("00. Active Customers").Cells(lastrow + 1, 36).Value = "No"
End If
'after checkboxes, now for textboxes
ThisWorkbook.Worksheets("00. Active Customers").Cells(lastrow + 1, 122).Value = txtFirstContact.Text
ThisWorkbook.Worksheets("00. Active Customers").Cells(lastrow + 1, 123).Value = txtLastContact.Text
End Sub
【问题讨论】:
-
你在哪一行得到错误?
-
嘿:)。在以 ThisWorkbook.Worksheets("00. Active Customers") 开头的第三行......
-
啊,当然:
Cells和Cells(row, column)一样使用,但你写的是Cells(lastrow + 1, 0)。问题是列编号以1开头,而0列不存在。 • 此外,我建议将Withstatement 用于With ThisWorkbook.Worksheets("00. Active Customers")。所以你不必一遍又一遍地重复。 -
非常感谢伙计!有效!但我不明白其他建议:)
-
作为答案发布。
标签: excel vba checkbox listbox userform