Monday, March 16, 2015

EXCEL SUMIF with OR condition

a simple workaround for using SUMIF with an OR condition:

- SUMIF returns a single Sum value from the Sum Range which matches the criteria set under Criteria. a work around is to use OR conditions in flower brackets separated by comma. 
- in this case the formula returns the value for the first condition mentioned in the flower bracket. it is not an error. the formula returns other values too but in a array form. to capture the complete value result of the formula in a single cell you would have precede it with a SUM formula. so the final output would look like this: 

 SUM(SUMIF(Criteria Range,{Criteria1, Criteria2, .. CriteriaN}, Sum Range))


this functionality can be extended for SUMIFS formula as well!

Thursday, February 12, 2015

Excel VBA Automation Error: The object invoked has disconnected from its clients

Error:
Excel VBA Automation Error: The object invoked has disconnected from its clients

Reason:
If you have come across above error, it would mainly because of 
        Selection.Insert Shift:=xlDown
statement in your vba code. 

i.e : you are trying to copy and insert the previous row which contains formulae. I know it would have been working flawlessly all these years but suddenly Excel felt like it needs have some fun playing with you. No problem, as we all know MS Excel has stretched beyond its capabilities let it have some fun. Now how to tame it..

Solution:
There are many workarounds suggested on many forums. But for me for the specific task of inserting the previous formulae filled rows down, I had to replace the Copy and xlDown code with a code to first insert as many blank rows that are required and then copy the formulae and paste over the new blank rows.

Now out of the blue why did Excel behave like this!!? Only possible reasoning could be corruption in excel sheet. Usually this error occurs in an old/used [or even abused] Excel Workbooks/Worksheets.

Hope this helps!
Have a good one! :)