excel - VBA Index/Match with multiple criteria (unique value & date) -
i have spreadsheet has values more 1 month, trying first find value based on value in wsrevfile worksheet , ensure value last month. when use following code, "invalid number of arguments" error.
sub revlookup(wsmvfile worksheet, wsrevold worksheet, wsnewrev worksheet, _ rowcount integer, workcol string, _ srccol1 integer, srccol2 integer) dim vrw variant, long = 2 rowcount vrw = application.match(wsrevfile.range("a" & i), wsnewrev.columns(2), format(dateserial(year(date), month(date), 0), "mm/dd/yyyy"), wsnewrev.columns(1), 0) if iserror(vrw) vrw = application.match(wsrevfile.range("a" & i), wsrevold.columns(1), 0) if not iserror(vrw) _ wsrevfile.range(workcol & i) = application.index(wsrevold.columns(srccol1), vrw) else wsrevfile.range(workcol & i) = application.index(wsnewrev.columns(srccol2), vrw, 1) end if next end sub
i assuming has way assigned application match function, because formula without part works other columns. ideas on how work?
thanks help!
try ajusting variables of following procedure, didn't figure out input , output data:
sub main() dim searchvalue variant dim searchcolumn range dim returncolumn range dim resultrows collection dim lastdate variant 'date? dim irow variant searchvalue = 10 '<-- change suit set searchcolumn = wsnewrev.range("b1:b10") set returncolumn = wsnewrev.range("c1:c10") '<-- change suit set resultrows = getlooprows(searchcolumn, searchvalue) each irow in resultrows if lastdate < returncolumn(irow) lastdate = returncolumn(irow) end if next irow debug.print lastdate end sub function getlooprows(paramarray pparameters() variant) collection 'obtém limites de laços com levando em conta condições '[vetor1], [valor1], [vetor2], [valor2], ... dim icondition long dim variant dim irow variant dim result collection dim numconditions long dim searchcollection collection dim arrayscollection collection dim iarray variant numconditions = (ubound(pparameters) - lbound(pparameters) + 1) / 2 set arrayscollection = new collection set searchcollection = new collection = lbound(pparameters) ubound(pparameters) step 2 arrayscollection.add pparameters(i + 0).value2 searchcollection.add pparameters(i + 1) next set result = new collection irow = lbound(arrayscollection(1)) ubound(arrayscollection(1)) icondition = 1 numconditions if arrayscollection(icondition)(irow, 1) <> searchcollection(icondition) goto continue next icondition result.add clng(irow) continue: next irow quit: set getlooprows = result end function
Comments
Post a Comment