【发布时间】:2018-01-08 19:52:07
【问题描述】:
我一直在尝试在表中搜索预定值,如果该值不存在,请添加该值,然后在表中创建一个新行。
我知道听起来很简单。
tblrow = tbllook.Range.Columns(1).Cells.Find(shtfind, searchorder:=xlByRows, searchdirection:=xlPrevious).Row
MsgBox tblrow
If tblrow Is Nothing Then
tblcount = tbllook.Range.Rows.Count
tbllook.Range(tblcount, 1).Select
ActiveCell = shtfind
tbllook.ListRows.Add
End If
Tblerow 目前作为变体变暗。
当我在表中找到它时,我在 msgbox 中得到了正确的答案,但随后在 If 语句中吐出“需要对象”错误。
但是当在表中找不到该值时,它仍然会吐出相同的错误。
我尝试将 tblrow 的 Dim 更改为 Object,然后在我的 .find 行上得到一个“对象变量或未设置块变量”,即使我将 set 放在它前面。
我对问题的谷歌搜索告诉我,这是因为它没有在表中找到值,并且我添加的 If 语句应该对它进行排序,但它没有。
请帮忙。
【问题讨论】:
-
请发布实际代码而不是图片
-
tblrow = tbllook.Range.Columns(1).Cells.Find(shtfind, searchorder:=xlByRows, searchdirection:=xlPrevious).Row MsgBox tblrow If tblrow is nothing then tblcount = tbllook.Range. Rows.Count tbllook.Range(tblcount, 1).Select ActiveCell = shtfind tbllook.ListRows.Add End If
-
我显然没有掌握这个论坛的格式的窍门..但这就是代码
-
请不要在 cmets 中发布相关信息,编辑您的问题并在此处添加信息。