Auto-Populating a form with SUMIF needing OR condition

Nathag

New Member
Joined
Aug 1, 2013
Messages
17
Hi all,

I am a VBA novice trying to get the syntax correct for auto-populating a form that I have where I need an OR condition, or something similar. In a regular workbook, this would be a matter of creating an array formula or adding two sumifs together.

I'm not as sure how that works in the VBA macro world and cannot seem to find specific examples of anyone doing anything similar.

Here is my current coding:
Code:
notsrc.Worksheets("Name_of_Worksheet").Range("D57").Value = WorksheetFunction.SumIfs(src.Worksheets("sheet1").Range("A3:A10000"), src.Worksheets("sheet1").Range("A3:A10000"), "=1", src.Worksheets("sheet1").Range("Y3:Y10000"), "=ABCD")

I found out that the company changed coding a few years ago, so there was a time when the ABCD coding in my spreadsheets in column Y simultaneously existed along with WXYZ coding for the same program.

I want to create something where by coding can sumifs on Y3:Y10000 if it equals either ABCD or WXYZ and ignore the rest of the codes. I have tried it a few different ways without getting the syntax correct, but the code works fine when I do not try to add an OR condition anywhere. Maybe I just need another long line of code and add the sumifs for WXYZ and ABCD togehter?
 
Last edited:

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
In order to get replies, maybe I just need to be a little more clear.

I want to populate cell D57 in the workbook declared as "notsrc" with data pulled from the workbook called "src" based on mutliple criteria where column A = 1 and column Y = ABCD or WXYZ.

The code I have works fine when I have just ABCD, but adding WXYZ in such a way that cell D57 will contain the sum of both has presented a challenge. I am a not a very good programmer, so I appreciate the help.

I am actually pulling data into one report from multiple workbooks spanning multiple years and timeframes, so the project is actually quite impressive, but it has been over a decade since I last touched VBA, so figuring this out will finally allow my project to move forward.
 
Last edited:
Upvote 0
I solved my own problem, but perhaps I wanted an easier way because I don't like massive lines of code for simple things.

I just added the SUMIFS like I mentioned in my first post.

The final solution looked like below. Essentially, add the sumifs for ABCD and WXYZ together.

notsrc.Worksheets("Name_of_Worksheet").Range("D57").Value = WorksheetFunction.SumIfs(src.Worksheets("sheet1").Range("A3:A10000"), src.Worksheets("sheet1").Range("A3:A10000"), "=1", src.Worksheets("sheet1").Range("Y3:Y10000"), "=ABCD") + WorksheetFunction.SumIfs(src.Worksheets("sheet1").Range("A3:A10000"), src.Worksheets("sheet1").Range("A3:A10000"), "=1", src.Worksheets("sheet1").Range("Y3:Y10000"), "=WXYZ")

Quite a beasty line of code though.
 
Upvote 0

Forum statistics

Threads
1,215,713
Messages
6,126,412
Members
449,314
Latest member
MrSabo83

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