来自另一篇帖子,combine rows with duplicates我收到了答案,但解析了评估行时遇到了问题。
mr = Application.Evaluate("MIN(INDEX(ROW(1:" & rw & ")+(('" & wsn & "'!B1:B" & rw & "<>'" & wsn & "'!B" & rw & ")+('" & wsn & "'!C1:C" & rw & "<>'" & wsn & "'!C" & rw & "))*1E+99, , ))")
我最初被困在
部分 INDEX(ROW(1:" & rw & ")
我知道Row函数提供了行号,但上面的语法是1:rw或??
的范围如果有人可以提供一个更简单的MIN示例(INDEX(ROW(...只有一些参数和解释非常有帮助。
答案 0 :(得分:1)
每当有疑问时,请在立即窗口中调试公式。这是一个例子
Sub Sample()
Dim sFormula As String
Dim rw As Long
Dim wsn As String
rw = 1 '<~~ Giving them some fictitious values. Give actual value if you have one
wsn = "Sid" '<~~ Giving them some fictitious values. Give actual value if you have one
sFormula = "MIN(INDEX(ROW(1:" & _
rw & _
")+(('" & _
wsn & _
"'!B1:B" & _
rw & _
"<>'" & _
wsn & _
"'!B" & _
rw & _
")+('" & _
wsn & _
"'!C1:C" & _
rw & _
"<>'" & _
wsn & _
"'!C" & _
rw & _
"))*1E+99, , ))"
Debug.Print sFormula
'mr = Application.Evaluate(sFormula)
End Sub
然后你会清楚这个公式:)
您甚至可以将该公式复制到新工作表中进行测试。