473,698 Members | 2,274 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Coding Sum If For Multiple Criteria

6 New Member
Hey everyone,

I need to find a value in a pivot table with a range of values over 12 months (Book5) when 3 criteria are met, Branch#, LOB# and Month#. Sum(if() works for the 1st month, but I do not know how to do the coding when the month changes.

Attached are copies of the two files I am working with and my coding so far.
Expand|Select|Wrap|Line Numbers
  1. Sub glvalueamount()
  2. Dim glvalue As Integer
  3. Dim glperiod As String
  4.  
  5. If (glperiod = "01") Then
  6.   glvalue = Selection.FormulaArray = "=SUM(IF([Book5]Sheet1!R6C1:R34C1=RC[-4],IF([Book5]Sheet1!R6C2:R34C2=RC[-3],IF([Book5]Sheet1!R4C3=RC[-5],[Book5]Sheet1!R6C7:R34C7,0),0)))"
  7. Else
  8.   If (glperiod = "02") Then
  9.     glvalue = Selection.FormulaArray = "=SUM(IF([Book5]Sheet1!R6C1:R34C1=RC[-4],IF([Book5]Sheet1!R6C2:R34C2=RC[-3],IF([Book5]Sheet1!R4C3=RC[-5],[Book5]Sheet1!R6C7:R34C7,0),0)))"
  10.     If (glperiod = "03") Then
  11.       glvalue = Selection.FormulaArray = "=SUM(IF([Book5]Sheet1!R6C1:R34C1=RC[-4],IF([Book5]Sheet1!R6C2:R34C2=RC[-3],IF([Book5]Sheet1!R4C3=RC[-5],[Book5]Sheet1!R6C7:R34C7,0),0)))"
  12.       If (glperiod = "04") Then
  13.         glvalue = Selection.FormulaArray = "=SUM(IF([Book5]Sheet1!R6C1:R34C1=RC[-4],IF([Book5]Sheet1!R6C2:R34C2=RC[-3],IF([Book5]Sheet1!R4C3=RC[-5],[Book5]Sheet1!R6C7:R34C7,0),0)))"
  14.         If (glperiod = "05") Then
  15.           glvalue = Selection.FormulaArray = "=SUM(IF([Book5]Sheet1!R6C1:R34C1=RC[-4],IF([Book5]Sheet1!R6C2:R34C2=RC[-3],IF([Book5]Sheet1!R4C3=RC[-5],[Book5]Sheet1!R6C7:R34C7,0),0)))"
  16.           If (glperiod = "06") Then
  17.             glvalue = Selection.FormulaArray = "=SUM(IF([Book5]Sheet1!R6C1:R34C1=RC[-4],IF([Book5]Sheet1!R6C2:R34C2=RC[-3],IF([Book5]Sheet1!R4C3=RC[-5],[Book5]Sheet1!R6C7:R34C7,0),0)))"
  18.             If (glperiod = "07") Then
  19.               glvalue = Selection.FormulaArray = "=SUM(IF([Book5]Sheet1!R6C1:R34C1=RC[-4],IF([Book5]Sheet1!R6C2:R34C2=RC[-3],IF([Book5]Sheet1!R4C3=RC[-5],[Book5]Sheet1!R6C7:R34C7,0),0)))"
  20.               If (glperiod = "08") Then
  21.                 glvalue = Selection.FormulaArray = "=SUM(IF([Book5]Sheet1!R6C1:R34C1=RC[-4],IF([Book5]Sheet1!R6C2:R34C2=RC[-3],IF([Book5]Sheet1!R4C3=RC[-5],[Book5]Sheet1!R6C7:R34C7,0),0)))"
  22.                 If (glperiod = "09") Then
  23.                   glvalue = Selection.FormulaArray = "=SUM(IF([Book5]Sheet1!R6C1:R34C1=RC[-4],IF([Book5]Sheet1!R6C2:R34C2=RC[-3],IF([Book5]Sheet1!R4C3=RC[-5],[Book5]Sheet1!R6C7:R34C7,0),0)))"
  24.                   If (glperiod = "10") Then
  25.                     glvalue = Selection.FormulaArray = "=SUM(IF([Book5]Sheet1!R6C1:R34C1=RC[-4],IF([Book5]Sheet1!R6C2:R34C2=RC[-3],IF([Book5]Sheet1!R4C3=RC[-5],[Book5]Sheet1!R6C7:R34C7,0),0)))"
  26.                     If (glperiod = "11") Then
  27.                       glvalue = Selection.FormulaArray = "=SUM(IF([Book5]Sheet1!R6C1:R34C1=RC[-4],IF([Book5]Sheet1!R6C2:R34C2=RC[-3],IF([Book5]Sheet1!R4C3=RC[-5],[Book5]Sheet1!R6C7:R34C7,0),0)))"
  28.                       If (glperiod = "12") Then
  29.                         glvalue = Selection.FormulaArray = "=SUM(IF([Book5]Sheet1!R6C1:R34C1=RC[-4],IF([Book5]Sheet1!R6C2:R34C2=RC[-3],IF([Book5]Sheet1!R4C3=RC[-5],[Book5]Sheet1!R6C7:R34C7,0),0)))"
  30.                       End If
  31.                     End If
  32.                   End If
  33.                 End If
  34.               End If
  35.             End If
  36.           End If
  37.         End If
  38.       End If
  39.     End If
  40.   End If
  41. End If
  42.  
  43. End Sub
Has anyone ever dealt with a similar challenge?

Thank you.

I do not know how to insert my files.
Oct 9 '07 #1
2 1950
kadghar
1,295 Recognized Expert Top Contributor
...

I do not know how to insert my files.
Hi!

I think that right after you post a reply, you can edit it, and while editing it you can manage your attachments.

i'd like to check the files, that could make things easier.
Oct 10 '07 #2
Killer42
8,435 Recognized Expert Expert
I think that right after you post a reply, you can edit it, and while editing it you can manage your attachments.
Yes, you have up to one hour to edit a message after you post it. During that time you can add or remove attachments by going to edit mode and hitting "Manage attachments".
Oct 10 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
21096
by: ShyGuy | last post by:
I have a table with 4 fields. Three are used for criteria. I can get the DLookup to work with 1 criteria with the following but can't get it to work with 2 or three. NumofAppts = DLookup("", "LookUpAppts", " = " & Forms!!NumofPeople) Can someone tell me how to add multiple criteria? I tried "And" but it doesn't seem to work.
0
3510
by: starace | last post by:
I have designed a form that has 5 different list boxes where the selections within each are used as criteria in building a dynamic query. Some boxes are set for multiple selections but these list boxes do not necessarily need to have a selection made to be used in the dynamic query. In essence the form can have selections made in all or none of its list boxes to form the dynamic query I am looking to get some feedback in reference to...
4
5367
by: carl.barrett | last post by:
Hi, I have a list box that displays 2 columns. Behind it sits a query with five columns. These are Column1 (DOB), column2 (a concatenated string of Surname Forname, Title), Column3 (Surname), column4 (Forename) and column5 (title). Columns 3,4 and 5 are not shown in the list box only the first two. DOB Name: &" "&&", "&
6
1768
by: NOSPAMrclark | last post by:
I'm wondering . . . . What is the generally accepted method for calling reports from multiple locations? Example: REPORT-A is called by selecting a record in a listbox and clicking a button. The queries behind the record use the listbox value (selected) as criteria to limit/build the report data.
0
2469
by: Greg Strong | last post by:
Hello All, In the past I've used a combo box with the 'row source' being an Access SQL union query to select "All" or 1 for only 1 criteria in a query. An example is as follows: SELECT 0 As PvdrID, "All" As PvdrDesc FROM tblPrvdr UNION SELECT PvdrID, PvdrDesc FROM tblPrvdr ORDER BY PvdrID; In the query I would place a field which wasn't selected for display which was
7
4949
by: Robert Seacord | last post by:
The CERT/CC has just deployed a new web site dedicated to developing secure coding standards for the C programming language, C++, and eventually other programming language. We have already developed significant content for the C programming language that is available at: https://www.securecoding.cert.org/ by clicking on the "CERT C Programming Language Secure Coding Standard"
7
4010
by: Ceebaby via AccessMonster.com | last post by:
Hi All Here's hoping someone can help me with this. I have a report based on a query where the criteria for 4 of the fields is set from an unbound form. I want the user to be able to select any combination of the combo boxes, some might not be selected etc etc. ie they may want to select the area and ward to show on the report but not the case officer or the property type
2
5561
by: dlevene | last post by:
Hi - newbie here, be gentle. In Access 2003, I've created a report (based on a query) to produce mailing labels for all records where = "Community". is a combo-box field with the values coming from a seperate table. Problem is, some of these don't have addresses (ie. , and are null). So I want to use the address of the Administrator for that community. This information is in records where = "Administrator" and = whatever the community...
3
3634
by: kstevens | last post by:
Please help. I know the sysntax is wrong. Here are some details. I am looking for the sum of past shipped items. I originally wrote this Dsum with only one criteria, but because of multiple lineitems with the same number it was adding all of the items with the same ....obviously. So i tried to just find records with multiple criteria..... part number (formatted as text) and the (formatted as number). Nz(DSum("shipqty",...
0
8672
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
8892
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8860
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7712
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4361
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3038
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
1998
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.