本文介绍了'结束(xlDown)'表现很奇怪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我怀疑 .end(xlDown)
有点奇怪。
Dim rfound As Range
Set rfound = Columns("B:B").Find(What:=Me.ComboBox1.Value, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext)
If ComboBox1.Value <> "" And WorksheetFunction.CountIf(Range("B:B"), _
ComboBox1.Value) > 0 And rfound.Offset(0, 1).Value <> "" Then
rfound.Offset(0, 1).End(xlDown).Offset(1, 0).Value = TextBox1.Value
在 CommandButton1_click
之后,代码将在列B中搜索任何匹配的条件,然后 OffSet
到正确的单元格,只要我的条件都得到满足。但是,它提示我一个消息运行时错误'1004':应用程序定义或对象定义的错误
。
Upon CommandButton1_click
, the code will search in the column B for any matched criteria and then OffSet
to the right cell provided my conditions are all met. However, it prompt me a message Run-time error '1004': Application defined or object-defined error
.
我没有任何线索问题在哪里。例如:
I have no clue where is the problem. For illustration:
推荐答案
您当前的代码
-
B2
asrfound
(注意:如果rfound
存在于查找
之后,如果没有rfound是没有的话) - 然后
C2
是rfound.Offset(0,1)
-
rfound.Offset(0,1).End(xlDown)
查找列C中的所有其他单元格为空的最后一个单元格 -
rfound.Offset(0,1).End(xlDown).Offset(1,0)
尝试在单元格的最后一行下方输入一个值 - 无法做到。 li>
- Presumably finds
B2
asrfound
(Note: It would be better to test ifrfound
exists after theFind
with `If Not rfound Is Nothing Then) - Then
C2
isrfound.Offset(0, 1)
rfound.Offset(0, 1).End(xlDown)
find the last cell in column C as all other cells are blankrfound.Offset(0, 1).End(xlDown).Offset(1, 0)
tries to enter a value in the cell one row below the very last row - no can do.
从底部查找,而不是
然后rfound.Offset(0,1).End(xlDown).Offset(1,0).Value = TextBox1.Value
使用
然后单元格(Rows.Count,rfound.O ffset(0,1).Column).End(xlUp).Offset(1,0)= TextBox1.Value
这篇关于'结束(xlDown)'表现很奇怪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!