大众信息网

vba翻译 这句代码什么意思

关注:289  答案:2  手机版
解决时间 2021-02-08 03:41
e = a - Range("ah1:al" & a - 1).Find(Cells(a, b), , xlValues, xlWhole, xlByRows, xlPrevious).row
运行时系统显示 对象变量或with块变量未设置
请大侠帮忙设置
谢谢 谢谢

For a = 1 To [a100].End(3).row
For b = 1 To 5
If Not Range("a" & a - 5 & ":e" & a - 1).Find(Cells(a, b), , xlValues, xlWhole, xlByRows, xlPrevious) Is Nothing Then

e = a - Range("a1:e" & a - 1).Find(Cells(a, b), , xlValues, xlWhole, xlByRows, xlPrevious).row

If e < 5 Then

Cells(a, b).Offset(0, 6) = Cells(a, b) & e
最佳答案
之所以提示:“对象变量或with块变量未设置”是因为你的If...then语句敲了回车键,如果需要敲回车键,If...then必须用End if 结尾,End if不能省略。改为如下即可:
For a = 6 To [a100].End(3).row
For b = 1 To 5
If Not Range("a" & a - 5 & ":e" & a - 1).Find(Cells(a, b), , xlValues, xlWhole, xlByRows, xlPrevious) Is Nothing Then
e = a - Range("a1:e" & a - 1).Find(Cells(a, b), , xlValues, xlWhole, xlByRows, xlPrevious).row
end if

If e < 5 Then

Cells(a, b).Offset(0, 6) = Cells(a, b) & e

End if
全部回答
函数chr(65)返回字符a,chr(66)返回字符b,chr(67)返回字符c。代码的意思是如果表1中a3、a4、a5三个单元格的值相等时,表2中a1等于表1的a3,否则等于0。b、c列同样处理。代码可如下简化: sub 执行() dim i as integer with sheets(1) for i = 1 to 3 sheets(2).cells(1, i)=iif(.cells(3, i) = .cells(4, i) and .cells(4, i) = .cells(5, i) , .cells(3, i),0) next end with end sub 代码已通过调试。
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!