Excel-VBA 命名范围行总和
我有以下代码
For i = 1 To DepRng.Rows.Count
For j = 1 To DepRng.Columns.Count
DepRng.Cells(i, j) = Application.Sum(KidsRng.Row(i)) //Does not work
Next j
Next i
虽然我知道这是错误的,但我不知道如何将其存储在 DepRng.Cells(i, j)
中整个 KidsRng.Row[我]
有什么帮助吗?
I have the following code
For i = 1 To DepRng.Rows.Count
For j = 1 To DepRng.Columns.Count
DepRng.Cells(i, j) = Application.Sum(KidsRng.Row(i)) //Does not work
Next j
Next i
Although I know is wrong, i have no idea how to get it to store in DepRng.Cells(i, j)
the total sum of the whole KidsRng.Row[i]
Any help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
下面的代码工作正常。
也许您应该将其与您的进行比较:
只需用数字填充范围 C1:F2,执行宏后每行的总计将显示在 B1:B2 中。
The following code works ok.
Perhaps you should compare it with yours:
Just fill the range C1:F2 with numbers and the totals per row will appear in B1:B2 upon execution of the macro.
已排序,感谢大家的帮助
Sorted, thanks all for ur help
可能有比这更好的方法,但这是我的解决方案,它取决于内部 Excel 公式引擎,但它可能足以满足您正在做的事情...它确定 KidsRng.Row(i) 的完整地址,并将其输入 =SUM() 公式字符串并由 Application.Evaluate 进行评估。
如果 kidsrng 存在于不同的工作表/书中,则更新它以使其工作
更新为使用 Application.Evaluate
There may be a better way than this, but this is my solution which depends on the internal Excel formula engine though, it might be sufficient enough for what you're doing... It determines the full address of KidsRng.Row(i), and feeds it into a =SUM() formula string and evaluated by Application.Evaluate.
updated it to work if kidsrng existed in a different sheet/book
updated to use Application.Evaluate