gpt4 book ai didi

vba - 运行时错误 91 对象变量或未设置变量

转载 作者:行者123 更新时间:2023-12-04 21:53:12 30 4
gpt4 key购买 nike

当代码到达'在数据库中查找第一个空行时,它会以黄色突出显示接下来的两行并显示运行时错误 91。谁能告诉我哪里出错了。谢谢你。

Private Sub diaryenter_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("sheet1")
'find first empty row in database
iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
'copy the data to the database
With ws
.Cells(iRow, 115).Value = Me.autodatet.Value
.Cells(iRow, 116).Value = Me.fdcomments.Value
.Cells(iRow, 121).Value = Me.fdgs.Value
End With
'clear the data
Me.autodatet.Value = ""
Me.fdcomments.Value = ""
Me.fdgs.Value = ""
Diaryentryf.Hide
ThisWorkbook.Save
End Sub

最佳答案

xlByRows不是 xlRows .

iRow = ws.Cells.Find(What:="*", SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1

关于vba - 运行时错误 91 对象变量或未设置变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50347482/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com