Excel用户表单 – 不读取或写入电子表格

我创build了一个新的用户表单,它将数据写入电子表格,然后使用下拉菜单将数据载入表单,供您编辑和重新保存。 当我点击保存它不会写入电子表格,当我预先填充电子表格,它不会然后加载到用户窗体。 我有下面的代码适用于类似的用户窗体,但不会为我正在编译的新的工作。 运行时没有错误信息。 我错过了什么?

Dim NotNow As Boolean Dim dropbuttonclicked As Boolean Private Sub cmd_Submit_Click() 'Submit Dim emptyRow As Long 'Make Sheet1 active Sheet1.Activate 'Determine emptyRow emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1 Dim RowCount As Long Dim ctl As Control ' inputs new project if no ref selected If Me.cboSearch.Value = "" Then Application.ScreenUpdating = False On Error GoTo WithRef With ActiveSheet If .AutoFilterMode Then .ShowAllData End If End With Else ' If a search is selected edit that line of data NotNow = True Application.ScreenUpdating = False ' unprotects the report On Error GoTo WithRef With ActiveSheet If .AutoFilterMode Then .ShowAllData End If End With WithRef: Worksheets("Sheet1").Activate If Me.cboSearch.Value = "" Then n = WorksheetFunction.CountA(Range("A:A")) + 1 Else n = Application.Match(Me.cboSearch.Value, Range("A:A"), 0) End If On Error GoTo Contnow 'Transfer information Cells(n, 1).Value = Log_No.Value Cells(n, 2).Value = Statement.Value Cells(n, 3).Value = Raised_By.Value Cells(n, 4).Value = Format(Raised_Date.Value, "mm/dd/yyyy") Cells(n, 5).Value = Action.Value Cells(n, 6).Value = Act_Owner.Value Cells(n, 7).Value = Rel_Ph.Value Cells(n, 8).Value = Cat.Value Cells(n, 9).Value = Status.Value Cells(n, 10).Value = Pos_Neg.Value Cells(n, 11).Value = Format(Trans_Date.Value, "mm/dd/yyyy") Cells(n, 12).Value = Ref.Value Contnow: ' clear data from the form For Each ctl In Me.Controls If TypeName(ctl) = "TextBox" Or TypeName(ctl) = "ComboBox" Or TypeName(ctl) = "DTPicker" Then ctl.Value = "" ElseIf TypeName(ctl) = "CheckBox" Then ctl.Value = False End If Next ctl ' Save and return to normal mode Application.ScreenUpdating = True 'ActiveWorkbook.Save Unload Me Project_LL_Form.Show vbModeless Exit Sub End If End Sub Private Sub cmd_Close_Click() Unload Me End Sub Private Sub cboSearch_Change() If NotNow Then Exit Sub 'if ref is blank then clear data from form If Me.cboSearch.Value = "" Then Unload Me Project_LL_Form.Show vbModeless Else ' bring in data based on ref in REF range vrange = "Log" Worksheets("Sheet1").Activate n = Application.Match(Me.cboSearch.Value, Range("A:A"), 0) On Error GoTo contkh 'Transfer information to the form 'Project Information transfer Log_No.Value = Cells(n, 1).Value Statement.Value = Cells(n, 2).Value Raised_By.Value = Cells(n, 3).Value Raised_Date.Value = Format(Cells(n, 4).Value, "mm/dd/yyyy") Action.Value = Cells(n, 5).Value Act_Owner.Value = Cells(n, 6).Value Rel_Ph.Value = Cells(n, 7).Value Cat.Value = Cells(n, 8).Value Status.Value = Cells(n, 9).Value Pos_Neg.Value = Cells(n, 10).Value Trans_Date.Value = Format(Cells(n, 11).Value, "mm/dd/yyyy") Ref.Value = Cells(n, 12).Value contkh: End If End Sub