[算表] 阵列公式循环只有第1笔正确

楼主: tina1688   2018-03-13 22:07:56
软件:excel2010
大大拍写
之前询问阵列公式写成VBA已经成功(洒花)
但是第2笔之后的发现数值是错误的
看VBA逐笔运算式,循环数值应该是正确的
但不知为何跑错误的值
档案/示意图/VBA如下
档案http://t.cn/RnPe5vE
示意图https://imgur.com/a/9MhAk
Sub test()
'判断地址不重复数量
ActiveSheet.Range("A1").Select
While ActiveCell.Value <> ""
kkk = ActiveCell.Row
ActiveSheet.Range("A" & kkk).Select
ActiveSheet.Range("V" & kkk) = "地址数"
ActiveSheet.Range("T" & kkk).Select
ActiveSheet.Range(Selection, Selection.End(xlDown)).Select
ADress_Row = Selection.Rows.Count '判断地址的区间
ActiveSheet.Range("V" & kkk + 1).Value = Application.Evaluate _
("=SUM(If(" & Range("T" & kkk + 1 & ":U" & ADress_Row).Address &
"<>"""",1/COUNTIF(" & Range("T" & kkk + 1 & ":U" & ADress_Row).Address & ","
& _
Range("T" & kkk + 1 & ":U" & ADress_Row).Address & ")))")
ActiveSheet.Range("A" & kkk + 1).Select
'判断选择下个档案名称在哪里
For kkk = ActiveCell.Row To ActiveCell.SpecialCells(xlLastCell).Row
Step 1
If ActiveSheet.Range("A" & kkk) <> "" Then Exit For
Next kkk
ActiveSheet.Range("A" & kkk).Select
Wend
End Sub
作者: soyoso (我是耀宗)   2018-03-13 22:16:00
变量aDress_row是计数selection的列数,evaluate内要以列号才是正确的要转为列号的话,再配合变量kkk所取得的列号

Links booklink

Contact Us: admin [ a t ] ucptt.com