本文介绍了帮助从用户表单编辑Excel工作表,帮助修复我的代码。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用microsoft excel和userforms为我的部门创建一个数据库。 我创建了一个基于我发现的另一个数据库。 在处理我的用户表单的SAVE EDIT按钮时,我不断收到"运行时错误'91'"。 "对象
变量或未设置块变量",调试器突出显示  findvalue = EmployeeDB.FF1.Value
,我在下面的代码中将其设为粗体。 任何帮助将不胜感激。 我的意图是能够根据在组合框中做出的选择将我的工作表中的数据带到我的用户表单,该部分工作得很好,现在我希望
能够在我的工作表中编辑该数据用户表单并将其保存回工作表,这是我遇到问题的地方。 谢谢

I am creating a database for my fire dept using microsoft excel and userforms.  I have created a database based off another i found.  While working on the SAVE EDIT button of my user form, i keep getting the "run-time error '91'" "object variable or with block variable not set", the debugger highlights findvalue = EmployeeDB.FF1.Valuewhich i have made bold in the code below.  Any help would be appreciated.  My intent is to be able to bring the data from my worksheet to my user form based on a selection made in a combo box, that part is working great, now i would like to be able to edit that data in my user form and save it back to the worksheet, this is where i am having problems.  Thank you

Private Sub CmdUpdate_Click( )

'声明变量

Dim findvalue As Range

Dim cNum As Integer

Dim Personell_Data As Worksheet

'保留在内存中并停止屏幕闪烁

Application.ScreenUpdating = False

设置Personell_Data = Sheet1

'检查对于值

如果CmbFF.Value =""然后

MsgBox"没有要编辑的数据"&b $ b退出子

结束如果

'清除组合框

'找到要编辑的行

设置findvalue = Personell_Data.Range(" B:B")。 _
$
查找(What:= EmployeeDB.FF1.Value,LookIn:= xlValues,LookAt:= xlWhole)

'更新值

findvalue = EmployeeDB.FF1.Value

findvalue.Offset(0,4)= EmployeeDB.FF3.Value

findvalue.Offset(0, 5)= EmployeeDB.FF4.Value

findvalue.Offset(0,6)= EmployeeDB.FF5.Value

findvalue.Offset(0,7)= EmployeeDB.FF6 .Value

findvalue.Offset(0,8)= EmployeeDB.FF7.Value

findvalue.Offset(0,9)= EmployeeDB.FF8.Value

findvalue.Offset(0,10)= EmployeeDB.FF9.Value

findvalue.Offset(0,11)= EmployeeDB.FF10.Value

findvalue。偏移量(0,15)= EmployeeDB.FF11.Value

findvalue.Offset(0,20)= EmployeeDB.FF12.Value

findvalue.Offset(0,21) = EmployeeDB.FF13.Value

findvalue.Offset(0,22)= EmployeeDB.FF14.Value

findvalue.Offset(0,23)= EmployeeDB.FF15.Value

findvalue.Offset(0,24)= EmployeeDB.FF16.Value

findvalue.Offset(0, 25)= EmployeeDB.FF17.Value

findvalue.Offset(0,26)= EmployeeDB.FF18.Value

findvalue.Offset(0,27)= EmployeeDB.FF19 .Value

findvalue.Offset(0,28)= EmployeeDB.FF20.Value

findvalue.Offset(0,29)= EmployeeDB.FF21.Value

findvalue.Offset(0,30)= EmployeeDB.FF22.Value

Private Sub CmdUpdate_Click()
'declare the variables
Dim findvalue As Range
Dim cNum As Integer
Dim Personell_Data As Worksheet
'hold in memory and stop screen flicker
Application.ScreenUpdating = False
Set Personell_Data = Sheet1
'check for values
If CmbFF.Value = "" Then
MsgBox "There is not data to edit"
Exit Sub
End If
'clear the combobox
'find the row to edit
Set findvalue = Personell_Data.Range("B:B"). _
Find(What:=EmployeeDB.FF1.Value, LookIn:=xlValues, LookAt:=xlWhole)
'update the values
findvalue = EmployeeDB.FF1.Value
findvalue.Offset(0, 4) = EmployeeDB.FF3.Value
findvalue.Offset(0, 5) = EmployeeDB.FF4.Value
findvalue.Offset(0, 6) = EmployeeDB.FF5.Value
findvalue.Offset(0, 7) = EmployeeDB.FF6.Value
findvalue.Offset(0, 8) = EmployeeDB.FF7.Value
findvalue.Offset(0, 9) = EmployeeDB.FF8.Value
findvalue.Offset(0, 10) = EmployeeDB.FF9.Value
findvalue.Offset(0, 11) = EmployeeDB.FF10.Value
findvalue.Offset(0, 15) = EmployeeDB.FF11.Value
findvalue.Offset(0, 20) = EmployeeDB.FF12.Value
findvalue.Offset(0, 21) = EmployeeDB.FF13.Value
findvalue.Offset(0, 22) = EmployeeDB.FF14.Value
findvalue.Offset(0, 23) = EmployeeDB.FF15.Value
findvalue.Offset(0, 24) = EmployeeDB.FF16.Value
findvalue.Offset(0, 25) = EmployeeDB.FF17.Value
findvalue.Offset(0, 26) = EmployeeDB.FF18.Value
findvalue.Offset(0, 27) = EmployeeDB.FF19.Value
findvalue.Offset(0, 28) = EmployeeDB.FF20.Value
findvalue.Offset(0, 29) = EmployeeDB.FF21.Value
findvalue.Offset(0, 30) = EmployeeDB.FF22.Value

推荐答案

If (findValue Is Nothing) Then
    Exit Sub    ' -- do something in exceptional case
End If




问候,


Regards,


这篇关于帮助从用户表单编辑Excel工作表,帮助修复我的代码。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 06:03