我目前有一个包含列表框,文本框和命令按钮的用户表单。当用户双击列表框中的一行时,应该将数据提取到userform中的所有文本框,以便用户能够编辑工作表(数据库)中的当前数据。截至目前,当"更新"单击命令按钮,系统已经可以覆盖主数据库(Sheet1)中的值但在userform中,而不是刷新列表框中的值,它会提示:
An Error has Occurred
The error number is: 1004
The extract range has a missing or invalid field name
Please notify the administrator
如何解决这个问题?下面是我的代码"更新"功能
'declare the variables
Dim findvalue As Range
Dim DataSH As Worksheet
'error handling
On Error GoTo errHandler:
'hold in memory and stop screen flicker
Application.ScreenUpdating = False
Set DataSH = Sheet1
'check for values
If Rep4.Value = "" Or Rep6.Value = "" Then
MsgBox "There is not data to edit"
Exit Sub
End If
'clear the listbox
lstReport.RowSource = ""
'find the row to edit
Set findvalue = DataSH.Range("A:A"). _
Find(What:=Me.Rep15.Value, LookIn:=xlValues, LookAt:=xlWhole)
'update the values
findvalue = Rep15.Value
findvalue.Offset(0, 1) = Me.Rep3.Value
findvalue.Offset(0, 5) = Me.Rep2.Value
findvalue.Offset(0, 6) = Me.Rep1.Value
findvalue.Offset(0, 7) = Me.Rep6.Value
findvalue.Offset(0, 8) = Me.Rep7.Value
findvalue.Offset(0, 9) = Me.Rep8.Value
findvalue.Offset(0, 16) = Me.Rep9.Value
findvalue.Offset(0, 17) = Me.Rep10.Value
findvalue.Offset(0, 18) = Me.Rep4.Value
findvalue.Offset(0, 19) = Me.Rep12.Value
findvalue.Offset(0, 20) = Me.Rep5.Value
findvalue.Offset(0, 21) = Me.Rep13.Value
findvalue.Offset(0, 22) = Me.Rep14.Value
findvalue.Offset(0, 23) = Me.Rep11.Value
'unprotect the worksheets for the advanced filter
'Unprotect_All
'filter the data
Sheet1.Range("A2").CurrentRegion.AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=Sheet6.Range("FilterData!$Y$1:$Z$2"), CopyToRange:=Sheet6.Range("FilterData!$A$2:$X$2"), _
Unique:=False
'if no data exists then clear the rowsource
If Sheet6.Range("Y2").Value = "" Then
lstReport.RowSource = ""
Else
'add the filtered data to the rowsource
lstReport.RowSource = DataSH.Range("FilterData").Address(external:=True)
End If
'return to sheet
Sheet1.Select
'Protect all sheets
'Protect_All
'error block
On Error GoTo 0
Exit Sub
errHandler:
'Protect all sheets
'Protect_All
'show error information in a messagebox
MsgBox "An Error has Occurred " & vbCrLf & _
"The error number is: " & Err.Number & vbCrLf & _
Err.Description & vbCrLf & "Please notify the administrator"