简体   繁体   English

VBA 数组索引匹配

[英]VBA Array Index Match

I've been trying to run an array formula to return a variable.我一直在尝试运行一个数组公式来返回一个变量。

On column BI have dates & times (mm/dd/yyyy hh:mm) and column C I have temperatures.在 BI 列上有日期和时间 (mm/dd/yyyy hh:mm) 和列 C 我有温度。 I want to look for a value greater than or equal to 215 on the temperature column "C".我想在温度列“C”上查找大于或等于 215 的值。

Dim TEMP215 As Variant
With Application.WorksheetFunction
TEMP215 = .Index(ActiveWorkbook.Sheets(1).Range("C2:C460"), .Match(True, ActiveWorkbook.Sheets(1).Range("C2:C460") >= 215, 0))
End With

If I write the formula just like that in a cell it works perfectly, running it with Ctrl + Shift + Enter.如果我像在单元格中那样编写公式,它会完美运行,使用 Ctrl + Shift + Enter 运行它。 I have tried the TEMP215 as variant, long, integer, double, single... pretty much everything without success...我已经尝试了 TEMP215 作为变体,长,integer,双,单......几乎一切都没有成功......

Try using the Evaluate method...尝试使用 Evaluate 方法...

Dim TEMP215 As Variant

With ActiveWorkbook.Sheets(1).Range("C2:C460")
    TEMP215 = Evaluate("INDEX(" & .Address(External:=True) & ",MATCH(TRUE," & .Address(External:=True) & ">=215,0))")
End With

Note that the Evaluate method has a 255 character limit.请注意,Evaluate 方法有 255 个字符的限制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM