vba语言中find 的用法

来源:百度知道 编辑:UC知道 时间:2024/07/07 06:06:33
各位高手,在使用EXCEL中的VBA时,遇到了用find找不到的问题。程序如下:
明明刚从第19列中把一个值给了mytmpcell,但又从此列中找到与mytmpcell的value相同的单元格,就找不到了。
并且,刚开始调试的时候还能够找到的。请帮忙解决一下。有分送的哟!
For j = 5 To worksub.Columns(19).Rows.Count '开始填写对应的单元格
Set mytmpcell = .Cells(j, 19)
If mytmpcell.Value <> "" Then
.Cells(j, 21).Value = .Cells(j, 19).Value
.Columns(22).Value = .Columns(19).Value
Set mycell = worksub.Columns(19).Find(What:=mytmpcell.Value, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, MatchByte:=False, SearchFormat:=False)

If Not (mycell Is Nothing) Then
If mytmpcell.Row = mycell.Row Then

sht4.Cells(i, 17).Value = .Cells(mycell.Row, 19).Value
sht4.Cells(i, 4).Value = .Cells(mycell.Row, 14).Value

你的算法有问题,不知道你要的目的是什么?
Set mycell = worksub.Columns(19).Find(mytmpcell.Value, , xlWhole)
一般只要整个匹配就行了,其它参数都可以省略。
如果全部是数字型 的,就可以写成
Set mycell = worksub.Columns(19).Find(mytmpcell.Value,xlValues)
建议你到论坛发帖:http://www.38duoffice.cn/bbs/
我在那等你,上传附件

把表格发到yymhy@163.com看一下。