如何定义某个范围内的地址/单元格位置

How to define an address/cell location thats in a range

提问人:kca062 提问时间:11/10/2023 更新时间:11/10/2023 访问量:47

问:

我正在尝试编写代码,该代码基本上为我执行线性插值并将结果吐出到电子邮件中。我已将第一列和顶行设置为它们自己的范围(不包括 3300)。每个都需要用户输入每个范围内的数字。正在对顶行执行插值。目前,我正在使用 Excel 查找工作表函数来查找用于插值的 x1。我的计划是然后使用 x1 的地址/单元格位置来获取所需的剩余插值值(x2、y1、y2),但我无法弄清楚在使用变量找到它时如何定义它的位置。

附件是表格的片段:Table of values

我目前只附加了代码的地址相关组件,但如果需要,我可以复制粘贴整个函数,谢谢!

Dim avgSourceActivity As Double, ContainerActivity As Double, NumbSources As Integer
NumbSources = ws1.Range("D9").Value

'defining search ranges and variable locations
Dim avgSourceActRange As Range
Set avgSourceActRange = ws2.Range("h5:af5")
Dim numbSourcesRange As Range
Set numbSourcesRange = ws2.Range("G6:G19")
ws1.Range("D12").Value = avgSourceActivity

'searches the first column for the value of NumbSources
Dim FoundSourceNumb As Range
Set FoundSourceNumb = Range(numbSourcesRange).Find(NumbSources)
'establishes bounds of source activity for linear interpolation
Dim LookupFormulaMin As Double, LookupFormulaMax As Double
LookupFormulaMin = WorksheetFunction.Lookup(avgSourceActivity, avgSourceActRange)
MsgBox (LookupFormulaMin)

'write something in here to define LookUpFormulaMin's cell location
'use it to get the x2 by shifting over one in the cell range
LookupFormulaMax = ws2.Cells(LookupFormulaMin.Row, LookupFormulaMin.Column + 1).Value
MsgBox (LookupFormulaMax)
Excel VBA 范围 线性插值

评论

0赞 Notus_Panda 11/10/2023
avgSourceActivity 没有给出值,而是使用了两次,你是打算改用的吗?据我所知,您也只会从查找中获取一个值,而不是范围,因此您将无法在其上使用 /,请使用 .而是 find 方法(就像您在它之前使用的那样)。如果我误解了什么,请告诉我。avgSourceActivity = ws1.Range("D12").Value.Row.Column
0赞 kca062 11/10/2023
啊,是的,avgSourceActivity 是一个计算值,我忘记包含代码片段,它不会影响相关代码的其余部分。
0赞 kca062 11/10/2023
Find.Method 将允许我获取可用于 LookupFormulaMax 的单元格位置?
0赞 Notus_Panda 11/10/2023
Find 方法为您提供了一个范围引用,您应该能够使用 and on,但我不知道您当时不能使用什么,因为无论如何这似乎都是您想要的。无论如何,您将在 ws2 中的 avgSourceActRange 上使用 Find 方法。.Row.Columnrng.Value
0赞 kca062 11/10/2023
虽然源编号是正确的,但对于插值中的其他值,可以通过从源编号向下降低特定行数来找到它们(这就是我使用地址/位置的原因

答: 暂无答案