我已经创建了一个宏变量active_search,我试图将其包含在evaluate函数中。但是,evaluate函数未输出正确的值。有人有关于如何做到这一点的建议吗?
代码:
' this accurately provides the cell reference for the formula below
active_search = Cells(i, search_col).Address
active_match = Cells(i, match_col).Address
MsgBox active_search ' = &B$3 (or row i)
MsgBox active_match ' = $A$3
' formulas for the criteria below
' check_search = [IFERROR(MATCH(B3,list_keywords,0),0)] << Note: this works correctly
check_search = [IFERROR(MATCH(active_search,list_keywords,0),0)]
check_match = [IFERROR(SEARCH("exact",active_match,0)]
MsgBox check_search ' currently = 0 but should be 2250
MsgBox check_match
谢谢!
答案 0 :(得分:0)
让我们来解释@simoco评论的内容。
[]
这是Evaluate
功能的快捷方式,不会对Variables
起作用。
为了使其有效,你必须明确地将它用作simoco在评论中所做的事情
要获得正确的值,请使用这些值(已由simoco提供)
check_search = Evaluate("IFERROR(MATCH(" & active_search & "list_keywords,0),0)")
'~~> provided that list_keywords is named Range
check_match = Evaluate("IFERROR(SEARCH(""exact""," & active_match & ",0),0)")
语法: 评估(名称),其中name
参数采用字符串形式。