VBA Sum( IF(Statement, if True, If False ) ) array function Syntax

MercuryVBA

Board Regular
Joined
Nov 12, 2013
Messages
56
Hello,

Would anyone be able to have me resolve the correct way to write this SUM ( IF() ) nested array function in VBA?

Code:
With Application.WorksheetFunction

.Sum(.IF(Sht2.Range("O2:O" & FinalRowSht2) = EmplID, Sht2.Range("AD2:AD" & FinalRowSht2), 0))

End With

I've defined "EmplID" and "FinalRowSht2" correctly earlier in the code - I'm excluding that definition here just to simplify

Many Thanks!
 
Check syntax is not a very amusing task ;)

But let me try...

Supposing it's inside

Code:
With WorksheetFunction
....
End With

As far as I know the structure of your formula seems correct.

In fact it depends on the values of
WSVP.Range("F3:" & WSVP.Cells(FinalRowWSVP, FinalColWSVP).Address
and
WSVP.Range("F2:" & WSVP.Cells(2, FinalColWSVP).Address

Could you tell us these values?

M.

M. seeing this through will be a learning experience for me - therefore, I'll provide the values for one current static instance (the range may expand dynamically hence the reason for dynamic definition)

Range(F3:AN3)
Range(F2:AN17)
 
Upvote 0

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
M. seeing this through will be a learning experience for me - therefore, I'll provide the values for one current static instance (the range may expand dynamically hence the reason for dynamic definition)

Range(F3:AN3)
Range(F2:AN17)

We have a problem

Take a look at the Help file and you can see that MATCH works only with one dimensional arrays (vectors in technical terms).
So probably you need to correct the Range(F2:AN17) to Range(F2:AN2) to be consistent with INDEX(F3:AN3,...

M.
 
Upvote 0
We have a problem

Take a look at the Help file and you can see that MATCH works only with one dimensional arrays (vectors in technical terms).
So probably you need to correct the Range(F2:AN17) to Range(F2:AN2) to be consistent with INDEX(F3:AN3,...

M.

M. You are right - the multi-dimension was throwing it off. Thank you again for everything!
 
Upvote 0

Forum statistics

Threads
1,216,084
Messages
6,128,724
Members
449,465
Latest member
TAKLAM

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top