excel - 如何将动态/VBA 生成的范围放入单元格的公式中?
问题描述
假设我们有这个代码
Dim runningTotal As Range
reference = Range("A4").Value
ThisWorkbook.Sheets(7).Range("A:JL").FormatConditions.Delete ' Delete current scales
For Each c In Worksheets("PVP Calculator").Range("A7:JL1506").Cells
' If c.Interior.colorIndex <> 0 Then
' c.Interior.colorIndex = 0
' End If
If c.Value = reference Then
' c.Interior.colorIndex = 6
If runningTotal Is Nothing Then
Set runningTotal = c
Else
Set runningTotal = Union(runningTotal, c)
End If
End If
Next
如何使单元格 B4 显示 runningTotal 范围内的最大值?做类似的事情是Range("B4").Value = MAX(runningTotal)
行不通的。
(起初单元格是相等的,但后来我更改了另一个单元格以使工作表的其余部分具有不同的值。此外,我打算更改c.Value = reference Then
为容差,我想这样吗?c.Value >= reference-5 And c.Value <= reference+5 Then
)
提前致谢。我花了半天时间没有使用正确的关键字搜索和浏览 MSDN 来弄清楚如何做我想做的事。
解决方案
我得到了答案,因为我在提交问题后继续搜索。它是Range("B4").Formula = "=MAX(" & runningTotal.Address & ")"
。我一开始在 & 连接中失败了,直到现在都忽略了 Address 属性
推荐阅读
- julia - 如何检查 Flux.jl 中的特征重要性?
- discord - 从 exc,discord.py 中引发 CommandInvokeError(exc)
- selenium - 如果超时如何让wait_until死
- vba - Microsoft Access 尝试在宏中查找表作为字段
- r - 在 summarise() 中过滤 n()
- java - 从数组中随机选择并删除 2 个不同的项目
- visual-studio - Visual Studio 2019 - “添加现有项目”功能中没有复制文件的选项
- bit-manipulation - 剩下大多数 mips
- django - Django 为通过查询集访问的对象提供不同的日期值
- javascript - 自定义函数未定义 Puppeteer