“For”语句中的 Excel Vba 错误

梅西1335

我在每个市场的每个报告中随机抽取 3% 的报告点击量……是的,别问了。无论如何 - 我已经设置并完成了代码,我将市场和报告设置为数组

例如:market = Array("market1", "market2","market3"...) report = Array("report1", "report2", "report3"...)

我的问题是,当我运行代码获得 3% 时,当该市场没有报告命中时 - 我得到了上一份报告的副本。

数据如下所示:

市场1 | 报告1 | #of 命中

市场1 | 报告2 | #of 命中

市场1 | 报告3 | #of 命中

市场2 | report1 |#of hits

市场2 | 报告1 | #of 命中

市场2 | 报告3 | #of 命中

如何消除之前数据的重复?

这是我的代码:

For i = 0 To UBound(market)
For z = 0 To UBound(report)

    
    reporthits = Application.CountIfs(ws2.Range("B:B"), market(i), ws2.Range("L:L"), report(z))
       
    If reporthits * 0.03 < 1 Then
    samplecount = 1
    Else
    samplecount = Round(reporthits * 0.03, 0)
    End If

    rownumber = ws2.Evaluate("IFERROR(Match(""" & market(i) & report(z) & """,B:B & L:L, 0),""Not Found"")")
        
    
    If IsNumeric(rownumber) Then

ws2.Range("$A" & rownumber & ":$L" & (rownumber + (samplecount - 1))).Copy
lrow3 = ws3.Range("A" & Rows.Count).End(xlUp).Row + 1
ws3.Range("A" & lrow3).PasteSpecial xlPasteAll

Else: Resume Next

谢谢!

斯科特·克雷纳

代替:

on error resume next
ws2.Range("$A" & rownumber & ":$L" & (rownumber + (samplecount - 1))).Copy

lrow3 = ws3.Range("A" & Rows.Count).End(xlUp).Row + 1
ws3.Range("A" & lrow3).PasteSpecial xlPasteAll

If Isnumeric(rownumber) Then
    ws2.Range("$A" & rownumber & ":$L" & (rownumber + (samplecount - 1))).Copy

    lrow3 = ws3.Range("A" & Rows.Count).End(xlUp).Row + 1
    ws3.Range("A" & lrow3).PasteSpecial xlPasteAll
End If

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章