目前我正在尝试采用复杂的Excel公式并转换为application.worksheetfunction
VBA流程,以便在代码执行期间进行评估。
我之前已经问过这个问题,我仍然很难总结出我需要修改的地方/内容,以便让它正确执行
基本上我采用下面的excel公式,并努力将其转换为具有动态单元格范围的VBA代码(同时$AM41
是动态的,并且会根据代码定义而改变)
=SUMIFS($N:$N,$B:$B,INDEX($B:$B,MAX(INDEX(($C:$C=$AM41)*ROW($C:$C),0))),$C:$C,$AM41)
到目前为止我的代码是这样的
Dim mws As Worksheet
Dim wf As WorksheetFunction
Dim mwsN As Range
Dim mwsC As Range
Dim mwsB As Range
Dim mwsLast As Range
Set wf = Application.WorksheetFunction
Set mws = Sheets("Marks")
Set mwsN = mws.Range("N:N")
Set mwsC = mws.Range("C:C")
Set mwsB = mws.Range("B:B")
LastMWSR = mws.Cells(mws.Rows.Count, "B").End(xlUp).Row
ClastMWSC = mws.Cells(1, mws.Columns.Count).End(xlToLeft).Column
Set mwsLast = mws.Cells(LastMWSR + 1, ClastMWSC - 1)
'error, is thrown just below this line
mws.Cells(LastMWSR + 1, ClastMWSC).Value = _
wf.SumIfs(mwsN, mwsB, wf.Index(mwsB, wf.Max(wf.Index((mwsC = mwsLast) * wf.Row(mwsC), 0))), mwsC, mwsLast)
我认为不匹配错误正在这里抛出
wf.Max(wf.Index((mwsC = mwsLast)
我不知道如何将该数组传达给VBA术语。
任何人都可以帮助说明如何使其动态化并清除不匹配错误吗?