Complicated SUMIFS formula help (VBA)

unicornsla

New Member
Joined
May 24, 2018
Messages
2
Hello all,

I am creating a UDF in VBA for a workbook. The workbook has two sheets: a Budget sheet and aPurchase Order (PO) sheet. Essentially, POs are entered into the PO sheet and the SUMIFS will go thru ALL the PO $ amounts and (hopefully) deduct the respective amounts from the proper account in the Budget sheet.

Code:
If desc Like "*CR#*" Then
    pos = InStr(1, desc, "CR")
    num = CStr(Val(Mid(desc, pos + 2, 2)))
    calcbudget = WorksheetFunction.SumIfs(POamts, POdesc, "*CR" & num & "*", POdesc, "<>*CR" & num & "#*", POcostel, costel, POwbs, wbs)

Above, I am trying to account for a situation where "...CR#..." appears in the description of aBudget account. That same "CR#" will appear in the description of any PO withdrawing from that Budget account. (That "POcostel, costel, POwbs, wbs" just deals with making sure the PO has the same general ledger account and WBS code as the Budget account we want to deduct from)

The problem is if a PO has description: "...CR301...", it will be deducted from the Budget account with description "...CR3...". I tried using the
Code:
"<>*CR" & num & "#*"
as another conditional but I'm not sure if the # wildcard has been removed.


Many thanks!
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
To clarify, below is an example of accounts from Budget:
Gjvc9Rf.png


...and suppose these are two purchase orders. I don't want the CR32 amount to get deducted from my "CR3 - Russia NRE" Budget account.
cyQ1RXc.png
 
Upvote 0

Forum statistics

Threads
1,216,460
Messages
6,130,765
Members
449,589
Latest member
Hana2911

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