SOLVED

Got stuck at creating a code for Ifna, sumif and sumproduct

%3CLINGO-SUB%20id%3D%22lingo-sub-3482082%22%20slang%3D%22en-US%22%3EGot%20stuck%20at%20creating%20a%20code%20for%20Ifna%2C%20sumif%20and%20sumproduct%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3482082%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20All%2C%20would%20like%20to%20create%26nbsp%3Ba%20code%20for%20Ifna%2C%20sumif%20and%20sumproduct.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETried%20to%20create%20a%20code%20replicate%20the%20excel%20formula%20below%3A%3C%2FP%3E%3CP%3EIFNA(IF(LEN(B1)%26gt%3B1%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESUMIF(Sheet1!E%3AI%2CB2%2CSheet1!I%3AI)%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESUMPRODUCT(MAX(--('%5BCredit%20Limit%20Requests%20(no%20existing%20SAP%20IDs).xlsx%5DNo%20SAP%20ID'!%24B2%3A%24B%3DB2)*--('%5BCredit%20Limit%20Requests%20(no%20existing%20SAP%20IDs).xlsx%5DNo%20SAP%20ID'!%24S2%3A%24S%3DSUMPRODUCT(MAX(--('%5BCredit%20Limit%20Requests%20(no%20existing%20SAP%20IDs).xlsx%5DNo%20SAP%20ID'!%24B2%3A%24B1000%3DB2)*'%5BCredit%20Limit%20Requests%20(no%20existing%20SAP%20IDs).xlsx%5DNo%20SAP%20ID'!%24S2%3A%24S)))*'%5BCredit%20Limit%20Requests%20(no%20existing%20SAP%20IDs).xlsx%5DNo%20SAP%20ID'!%24M2%3A%24M)))%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%22Credit%20limit%20not%20provided%20to%20this%20customer%22)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EGot%20stuck%20whilst%20trying%20to%20create%20the%20code%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E1st%20hurdle%3A%20To%20insert%20the%20IF%20into%20IFNA%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-visual-basic%22%3E%3CCODE%3Ews.Range(%22C44%22)%20%3D%20WorksheetFunction.IfNa(%20_%0AIf%20Len(ws.Range(%22C10%22))%20%26gt%3B%201%20Then%0AWorksheetFunction.SumIf(exA%2C%20ws.Range(%22C15%22)%2C%20exB)%0AElse%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E2nd%20hurdle%3A%20No%20clue%20how%20to%20insert%20a%20MsgBox%20if%20value%20equals%20%23N%2FA%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-visual-basic%22%3E%3CCODE%3EMsgBox%20%22Credit%20limit%20not%20provided%20to%20this%20customer%22%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-visual-basic%22%3E%3CCODE%3EDim%20ws%20As%20Worksheet%20'current%20sheet%0ADim%20exportWb%20As%20Workbook%0ADim%20clRequestWb%20As%20Workbook%0ADim%20exportWs%20As%20Worksheet%0ADim%20clRequestWs%20As%20Worksheet%0ADim%20exportWslastRow%20As%20Long%0A%0ADim%20exA%20As%20Range%0ADim%20exB%20As%20Range%0ADim%20cLB%20As%20Range%0ADim%20cLS%20As%20Range%0ADim%20cLM%20As%20Range%0A%0A%0ASet%20ws%20%3D%20Sheet1%0ASet%20exportWb%20%3D%20Workbooks.Open(Environ(%22Userprofile%22)%20%26amp%3B%20%22%5CDesktop%5Cexport.xlsx%22)%0ASet%20exportWs%20%3D%20exportWb.Sheets(%22Sheet1%22)%0AexportWslastRow%20%3D%20exportWs.Cells(exportWs.Rows.Count%2C%20%22B%22).End(xlUp).Row%0A%0ASet%20exA%20%3D%20exportWs.Range(%22E2%3AI%22%20%26amp%3B%20exportWslastRow)%0ASet%20exB%20%3D%20exportWs.Range(%22I2%3AI%22%20%26amp%3B%20exportWslastRow)%0A%0ASet%20clRequestWb%20%3D%20Workbooks.Open(%22V%3A%5CFinance%5CSystems-Risk-ERM%5COrderToCash%5CC2C%5CCorp%20Credit%20Control%5C1.%20Credit%20Limit%20Requests%5CCredit%20Limit%20Requests%20(no%20existing%20SAP%20IDs).xlsx%22)%0ASet%20clRequestWb%20%3D%20ActiveWorkbook%0ASet%20clRequestWs%20%3D%20clRequestWb.Sheets(%22No%20SAP%20ID%22)%0AThisWorkbook.Activate%0A%0ASet%20cLB%20%3D%20clRequestWs.Cells(clRequestWs.Rows.Count%2C%20%22B%22).End(xlUp).Row%0ASet%20cLS%20%3D%20clRequestWs.Cells(clRequestWs.Rows.Count%2C%20%22S%22).End(xlUp).Row%0ASet%20cLM%20%3D%20clRequestWs.Cells(clRequestWs.Rows.Count%2C%20%22M%22).End(xlUp).Row%0A%0Aws.Range(%22C44%22)%20%3D%20WorksheetFunction.IfNa(%20_%0A%0AIf%20Len(ws.Range(%22C10%22))%20%26gt%3B%201%20Then%0A%0AWorksheetFunction.SumIf(exA%2C%20ws.Range(%22C15%22)%2C%20exB)%0A%0AElse%0A%0AApplication.WorksheetFunction.SumProduct%20(WorksheetFunction.Max(--(cLB%20%3D%20clRequestWs.Range(%22B2%22))%20*%0A--(cLS%20%3D%20Application.WorksheetFunction.SumProduct(WorksheetFunction.Max(--(cLB%20%3D%20clRequestWs.Range(%22B2%22))%20*%20_%0AcLS)))%20*%20cLM))%0A%0AEnd%20If%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20in%20advance%20and%20appreciate%20the%20help%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-3482082%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3485232%22%20slang%3D%22en-US%22%3ERe%3A%20Got%20stuck%20at%20creating%20a%20code%20for%20Ifna%2C%20sumif%20and%20sumproduct%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3485232%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F127945%22%20target%3D%22_blank%22%3E%40Hans%20Vogelaar%3C%2FA%3E%26nbsp%3B%2C%20i%20tried%20the%20following%20but%20there%20is%20some%20issues%20with%20structuring%20of%20the%20code.%20Would%20you%20be%20able%20to%20assist%20on%20this%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3EDim%20i%20as%20Variant%0Ai%20%3D%20ws.Range(%22C44%22)%0A%0Ai%20%3D%20WorksheetFunction.IfNa(%0AIf%20Len(ws.Range(%22C10%22))%20%26gt%3B%201%20Then%0AWorksheetFunction.SumIf(exA%2C%20ws.Range(%22C15%22)%2C%20exB)%3A%3D%20%20%20%20%20%20%20%20%20%20%0AElse%0AApplication.WorksheetFunction.SumProduct%20(WorksheetFunction.Max(--(cLB%20%3D%20clRequestWs.Range(%22B2%22))%20*%0A--(cLS%20%3D%20Application.WorksheetFunction.SumProduct(WorksheetFunction.Max(--(cLB%20%3D%20clRequestWs.Range(%22B2%22))%20*%20_%0AcLS)))%20*%20cLM))%0A%0AEnd%20If%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3487443%22%20slang%3D%22en-US%22%3ERe%3A%20Got%20stuck%20at%20creating%20a%20code%20for%20Ifna%2C%20sumif%20and%20sumproduct%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3487443%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1393409%22%20target%3D%22_blank%22%3E%40hrh_dash%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWhy%20don't%20you%20just%20place%20the%20formula%20in%20the%20cell%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3487543%22%20slang%3D%22en-US%22%3ERe%3A%20Got%20stuck%20at%20creating%20a%20code%20for%20Ifna%2C%20sumif%20and%20sumproduct%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3487543%22%20slang%3D%22en-US%22%3EThe%20file%20will%20be%20used%20across%20the%20whole%20team%20and%20do%20not%20wish%20for%20the%20formula%20to%20be%20meddle%20with%20%3CLI-EMOJI%20id%3D%22lia_disappointed-face%22%20title%3D%22%3Adisappointed_face%3A%22%3E%3C%2FLI-EMOJI%3E%20it%20will%20also%20be%20sent%20to%20external%20service%20provider%20vendors%20to%20help%20enhance%20the%20whole%20credit%20assessment%20process..%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3487586%22%20slang%3D%22en-US%22%3ERe%3A%20Got%20stuck%20at%20creating%20a%20code%20for%20Ifna%2C%20sumif%20and%20sumproduct%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3487586%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1393409%22%20target%3D%22_blank%22%3E%40hrh_dash%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESee%20if%20this%20does%20what%20you%20want%3A%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-visual-basic%22%3E%3CCODE%3E%20%20%20%20Dim%20ws%20As%20Worksheet%0A%20%20%20%20Set%20ws%20%3D%20Sheet1%0A%20%20%20%20With%20ws.Range(%22C44%22)%0A%20%20%20%20%20%20%20%20.Formula%20%3D%20%22%3DIFNA(IF(LEN(C10)%26gt%3B1%2CSUMIF(Sheet1!E%3AI%2CC15%2CSheet1!I%3AI)%2C%22%20%26amp%3B%20_%0A%20%20%20%20%20%20%20%20%20%20%20%20%22SUMPRODUCT(MAX(('%5BCredit%20Limit%20Requests%20(no%20existing%20SAP%20IDs).xlsx%5DNo%20SAP%20ID'!%24B2%3A%24B%3DB2)*%22%20%26amp%3B%20_%0A%20%20%20%20%20%20%20%20%20%20%20%20%22('%5BCredit%20Limit%20Requests%20(no%20existing%20SAP%20IDs).xlsx%5DNo%20SAP%20ID'!%24S2%3A%24S%3D%22%20%26amp%3B%20_%0A%20%20%20%20%20%20%20%20%20%20%20%20%22SUMPRODUCT(MAX(--('%5BCredit%20Limit%20Requests%20(no%20existing%20SAP%20IDs).xlsx%5DNo%20SAP%20ID'!%24B2%3A%24B1000%3DB2)*%22%20%26amp%3B%20_%0A%20%20%20%20%20%20%20%20%20%20%20%20%22'%5BCredit%20Limit%20Requests%20(no%20existing%20SAP%20IDs).xlsx%5DNo%20SAP%20ID'!%24S2%3A%24S)))*%22%20%26amp%3B%20_%0A%20%20%20%20%20%20%20%20%20%20%20%20%22'%5BCredit%20Limit%20Requests%20(no%20existing%20SAP%20IDs).xlsx%5DNo%20SAP%20ID'!%24M2%3A%24M)))%2C%22%20%26amp%3B%20_%0A%20%20%20%20%20%20%20%20%20%20%20%20%22%22%22Credit%20limit%20not%20provided%20to%20this%20customer%22%22)%22%0A%20%20%20%20%20%20%20%20.Value%20%3D%20.Value%0A%20%20%20%20End%20With%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3487699%22%20slang%3D%22en-US%22%3ERe%3A%20Got%20stuck%20at%20creating%20a%20code%20for%20Ifna%2C%20sumif%20and%20sumproduct%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3487699%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F127945%22%20target%3D%22_blank%22%3E%40Hans%20Vogelaar%3C%2FA%3E%26nbsp%3B%2C%3C%2FP%3E%3CP%3Eis%20possible%20to%20substitute%20Sheet1%20with%20the%20exportWs%3F%20Because%20it%20is%20a%20file%20path%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-visual-basic%22%3E%3CCODE%3ESet%20exportWb%20%3D%20Workbooks.Open(Environ(%22Userprofile%22)%20%26amp%3B%20%22%5CDesktop%5Cexport.xlsx%22)%0ASet%20exportWs%20%3D%20exportWb.Sheets(%22Sheet1%22)%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3Eand%3C%2FP%3E%3CP%3E'%5BCredit%20Limit%20Requests%20(no%20existing%20SAP%20IDs).xlsx%5D%20as%26nbsp%3BclRequestWs%3F%20Because%20it%20is%20a%20file%20path.%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-visual-basic%22%3E%3CCODE%3ESet%20clRequestWb%20%3D%20Workbooks.Open(%22V%3A%5CFinance%5CSystems-Risk-ERM%5COrderToCash%5CC2C%5CCorp%20Credit%20Control%5C1.%20Credit%20Limit%20Requests%5CCredit%20Limit%20Requests%20(no%20existing%20SAP%20IDs).xlsx%22)%0ASet%20clRequestWb%20%3D%20ActiveWorkbook%0ASet%20clRequestWs%20%3D%20clRequestWb.Sheets(%22No%20SAP%20ID%22)%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3487814%22%20slang%3D%22en-US%22%3ERe%3A%20Got%20stuck%20at%20creating%20a%20code%20for%20Ifna%2C%20sumif%20and%20sumproduct%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3487814%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1393409%22%20target%3D%22_blank%22%3E%40hrh_dash%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20you%20open%20the%20workbooks%20in%20the%20code%2C%20the%20formula%20should%20work%20without%20specifying%20the%20path.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3488306%22%20slang%3D%22en-US%22%3ERe%3A%20Got%20stuck%20at%20creating%20a%20code%20for%20Ifna%2C%20sumif%20and%20sumproduct%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3488306%22%20slang%3D%22en-US%22%3Ethe%20code%20works!%3CBR%20%2F%3E%3CBR%20%2F%3Edownside%20is%20that%20the%3CBR%20%2F%3E%3CBR%20%2F%3E1.desktop%20file%20path%20cannot%20be%20replace%20by%20(Environ(%22Userprofile%22)%2C%20thus%20needs%20to%20be%20hard%20coded%20by%20the%20respective%20file%20path%3CBR%20%2F%3E%3CBR%20%2F%3E2.%20the%20ranges%20for%20sumproduct%20for%20workbook%20Credit%20Limit%20Requests%20(no%20existing%20SAP%20IDs)%20cannot%20be%20replace%20by%20clRequestWs.Cells(clRequestWs.Rows.Count%2C%20%22B%22)%20%2C%20clRequestWs.Cells(clRequestWs.Rows.Count%2C%20%22S%22)%20and%20clRequestWs.Cells(clRequestWs.Rows.Count%2C%20%22M%22)%2C%20hence%20it%20needs%20to%20be%20hard%20coded.%3CBR%20%2F%3E%3CBR%20%2F%3Eis%20there%20any%20other%20work%20around%20way%3F%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3489192%22%20slang%3D%22en-US%22%3ERe%3A%20Got%20stuck%20at%20creating%20a%20code%20for%20Ifna%2C%20sumif%20and%20sumproduct%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3489192%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1393409%22%20target%3D%22_blank%22%3E%40hrh_dash%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIt%20shouldn't%20really%20matter%2C%20and%20trying%20to%20refine%20the%20formula%20only%20complicates%20things.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3490507%22%20slang%3D%22en-US%22%3ERe%3A%20Got%20stuck%20at%20creating%20a%20code%20for%20Ifna%2C%20sumif%20and%20sumproduct%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3490507%22%20slang%3D%22en-US%22%3EAlright%20noted%2C%20thanks%20for%20the%20help%20again.%20Much%20appreciated%3C%2FLINGO-BODY%3E
Contributor

Hi All, would like to create a code for Ifna, sumif and sumproduct. 

 

Tried to create a code replicate the excel formula below:

IFNA(IF(LEN(B1)>1,

 

SUMIF(Sheet1!E:I,B2,Sheet1!I:I),

 

SUMPRODUCT(MAX(--('[Credit Limit Requests (no existing SAP IDs).xlsx]No SAP ID'!$B2:$B=B2)*--('[Credit Limit Requests (no existing SAP IDs).xlsx]No SAP ID'!$S2:$S=SUMPRODUCT(MAX(--('[Credit Limit Requests (no existing SAP IDs).xlsx]No SAP ID'!$B2:$B1000=B2)*'[Credit Limit Requests (no existing SAP IDs).xlsx]No SAP ID'!$S2:$S)))*'[Credit Limit Requests (no existing SAP IDs).xlsx]No SAP ID'!$M2:$M))),

 

"Credit limit not provided to this customer")

 

Got stuck whilst trying to create the code:

 

 

 

1st hurdle: To insert the IF into IFNA

 

 

ws.Range("C44") = WorksheetFunction.IfNa( _
If Len(ws.Range("C10")) > 1 Then
WorksheetFunction.SumIf(exA, ws.Range("C15"), exB)
Else

 

 

 

2nd hurdle: No clue how to insert a MsgBox if value equals #N/A

 

 

MsgBox "Credit limit not provided to this customer"

 

 

 

 

Dim ws As Worksheet 'current sheet
Dim exportWb As Workbook
Dim clRequestWb As Workbook
Dim exportWs As Worksheet
Dim clRequestWs As Worksheet
Dim exportWslastRow As Long

Dim exA As Range
Dim exB As Range
Dim cLB As Range
Dim cLS As Range
Dim cLM As Range


Set ws = Sheet1
Set exportWb = Workbooks.Open(Environ("Userprofile") & "\Desktop\export.xlsx")
Set exportWs = exportWb.Sheets("Sheet1")
exportWslastRow = exportWs.Cells(exportWs.Rows.Count, "B").End(xlUp).Row

Set exA = exportWs.Range("E2:I" & exportWslastRow)
Set exB = exportWs.Range("I2:I" & exportWslastRow)

Set clRequestWb = Workbooks.Open("V:\Finance\Systems-Risk-ERM\OrderToCash\C2C\Corp Credit Control\1. Credit Limit Requests\Credit Limit Requests (no existing SAP IDs).xlsx")
Set clRequestWb = ActiveWorkbook
Set clRequestWs = clRequestWb.Sheets("No SAP ID")
ThisWorkbook.Activate

Set cLB = clRequestWs.Cells(clRequestWs.Rows.Count, "B").End(xlUp).Row
Set cLS = clRequestWs.Cells(clRequestWs.Rows.Count, "S").End(xlUp).Row
Set cLM = clRequestWs.Cells(clRequestWs.Rows.Count, "M").End(xlUp).Row

ws.Range("C44") = WorksheetFunction.IfNa( _

If Len(ws.Range("C10")) > 1 Then

WorksheetFunction.SumIf(exA, ws.Range("C15"), exB)

Else

Application.WorksheetFunction.SumProduct (WorksheetFunction.Max(--(cLB = clRequestWs.Range("B2")) *
--(cLS = Application.WorksheetFunction.SumProduct(WorksheetFunction.Max(--(cLB = clRequestWs.Range("B2")) * _
cLS))) * cLM))

End If

 

Thanks in advance and appreciate the help

9 Replies

@Hans Vogelaar , i tried the following but there is some issues with structuring of the code. Would you be able to assist on this?

 

Dim i as Variant
i = ws.Range("C44")

i = WorksheetFunction.IfNa(
If Len(ws.Range("C10")) > 1 Then
WorksheetFunction.SumIf(exA, ws.Range("C15"), exB):=          
Else
Application.WorksheetFunction.SumProduct (WorksheetFunction.Max(--(cLB = clRequestWs.Range("B2")) *
--(cLS = Application.WorksheetFunction.SumProduct(WorksheetFunction.Max(--(cLB = clRequestWs.Range("B2")) * _
cLS))) * cLM))

End If

 

@hrh_dash 

 

Why don't you just place the formula in the cell?

The file will be used across the whole team and do not wish for the formula to be meddle with it will also be sent to external service provider vendors to help enhance the whole credit assessment process..
best response confirmed by hrh_dash (Contributor)
Solution

@hrh_dash 

See if this does what you want:

    Dim ws As Worksheet
    Set ws = Sheet1
    With ws.Range("C44")
        .Formula = "=IFNA(IF(LEN(C10)>1,SUMIF(Sheet1!E:I,C15,Sheet1!I:I)," & _
            "SUMPRODUCT(MAX(('[Credit Limit Requests (no existing SAP IDs).xlsx]No SAP ID'!$B2:$B=B2)*" & _
            "('[Credit Limit Requests (no existing SAP IDs).xlsx]No SAP ID'!$S2:$S=" & _
            "SUMPRODUCT(MAX(--('[Credit Limit Requests (no existing SAP IDs).xlsx]No SAP ID'!$B2:$B1000=B2)*" & _
            "'[Credit Limit Requests (no existing SAP IDs).xlsx]No SAP ID'!$S2:$S)))*" & _
            "'[Credit Limit Requests (no existing SAP IDs).xlsx]No SAP ID'!$M2:$M)))," & _
            """Credit limit not provided to this customer"")"
        .Value = .Value
    End With

@Hans Vogelaar ,

is possible to substitute Sheet1 with the exportWs? Because it is a file path

Set exportWb = Workbooks.Open(Environ("Userprofile") & "\Desktop\export.xlsx")
Set exportWs = exportWb.Sheets("Sheet1")

and

'[Credit Limit Requests (no existing SAP IDs).xlsx] as clRequestWs? Because it is a file path. 

Set clRequestWb = Workbooks.Open("V:\Finance\Systems-Risk-ERM\OrderToCash\C2C\Corp Credit Control\1. Credit Limit Requests\Credit Limit Requests (no existing SAP IDs).xlsx")
Set clRequestWb = ActiveWorkbook
Set clRequestWs = clRequestWb.Sheets("No SAP ID")

 

@hrh_dash 

If you open the workbooks in the code, the formula should work without specifying the path.

the code works!

downside is that the

1.desktop file path cannot be replace by (Environ("Userprofile"), thus needs to be hard coded by the respective file path

2. the ranges for sumproduct for workbook Credit Limit Requests (no existing SAP IDs) cannot be replace by clRequestWs.Cells(clRequestWs.Rows.Count, "B") , clRequestWs.Cells(clRequestWs.Rows.Count, "S") and clRequestWs.Cells(clRequestWs.Rows.Count, "M"), hence it needs to be hard coded.

is there any other work around way?

@hrh_dash 

It shouldn't really matter, and trying to refine the formula only complicates things.

Alright noted, thanks for the help again. Much appreciated