I understand how SUMIFS works in Excel, but I cannot figure out how it works in VBA.
Ideally I want the code to do the following:
Input Box appears and asks user to enter in the year in which they would like to see the totals for. That year is stored as "strYear" and used throughout the VBA code.
The title of the document is Concatenated and will state (strYear + " Totals").
Then, a few cells down from the title, would be a SUM of a range on a different sheet, only added if it meets three different criteria (Year - as the user specified, Target Area - as the code specifies, and Type of Product - as the code specifies). I need every row in this database to be checked and the ones that meet the criteria to be totaled on the Totals page for the manager to see. Also the database adds rows to the bottom of the database, so it is always growing.
There are multiple totals that I need and I can't figure out how to put a code together to make this happen. I will also need to do the same concept but with COUNT, to see how many times a record of certain criteria has occurred.
This is my VBA code at the moment.
I have done the first two parts of what I would like the overall code to accomplish, and have specified the ranges of the criteria to be searched.
Sub Totals()
Dim strYear As String
Dim rStartPosition As Range
Dim Title As String
Sheets("Totals").Select
strYear = InputBox("Nutrients Applied and Active Ingredient Totals. Please enter year.", "Totals")
Title = strYear + " Totals"
Sheets("Totals").Select
Range("A3").Select
ActiveCell = Title
Dim AppDBSumRangeStart As Range
Dim AppDBSumRangeEnd
Sheets("Application Database").Select
Range("N4").Select
Set AppDBSumRangeStart = Application.ActiveCell
Do Until ActiveCell = ""
ActiveCell.Offset(1, 0).Select
Loop
ActiveCell.Offset(-1, 0).Select
Set AppDBSumRangeEnd = Application.ActiveCell
Dim AppDBYearRangeStart As Range
Dim AppDBYearRangeEnd As Range
Sheets("Application Database").Select
Range("AA4").Select
Set AppDBYearRangeStart = Application.ActiveCell
Do Until ActiveCell = ""
ActiveCell.Offset(1, 0).Select
Loop
ActiveCell.Offset(-1, 0).Select
Set AppDBYearRangeEnd = Application.ActiveCell
Dim AppDBTargetAreaRangeStart As Range
Dim AppDBTargetAreaRangeEnd As Range
Sheets("Application Database").Select
Range("D4").Select
Set AppDBTargetAreaRangeStart = Application.ActiveCell
Do Until ActiveCell = ""
ActiveCell.Offset(1, 0).Select
Loop
ActiveCell.Offset(-1, 0).Select
Set AppDBTargetAreaRangeEnd = Application.ActiveCell
Dim AppDBTypeRangeStart As Range
Dim AppDBTypeRangeEnd As Range
Sheets("Application Database").Select
Range("D4").Select
Set AppDBTypeRangeStart = Application.ActiveCell
Do Until ActiveCell = ""
ActiveCell.Offset(1, 0).Select
Loop
ActiveCell.Offset(-1, 0).Select
Set AppDBTypeRangeEnd = Application.ActiveCell
Sheets("Totals").Select
Range("C8").Select
'**This is the cell where I want the SUMIFs function to show the result.**
End Sub
***************************************
Any help is greatly appreciated!
Thanks in advanced!
Ideally I want the code to do the following:
Input Box appears and asks user to enter in the year in which they would like to see the totals for. That year is stored as "strYear" and used throughout the VBA code.
The title of the document is Concatenated and will state (strYear + " Totals").
Then, a few cells down from the title, would be a SUM of a range on a different sheet, only added if it meets three different criteria (Year - as the user specified, Target Area - as the code specifies, and Type of Product - as the code specifies). I need every row in this database to be checked and the ones that meet the criteria to be totaled on the Totals page for the manager to see. Also the database adds rows to the bottom of the database, so it is always growing.
There are multiple totals that I need and I can't figure out how to put a code together to make this happen. I will also need to do the same concept but with COUNT, to see how many times a record of certain criteria has occurred.
This is my VBA code at the moment.
I have done the first two parts of what I would like the overall code to accomplish, and have specified the ranges of the criteria to be searched.
Sub Totals()
Dim strYear As String
Dim rStartPosition As Range
Dim Title As String
Sheets("Totals").Select
strYear = InputBox("Nutrients Applied and Active Ingredient Totals. Please enter year.", "Totals")
Title = strYear + " Totals"
Sheets("Totals").Select
Range("A3").Select
ActiveCell = Title
Dim AppDBSumRangeStart As Range
Dim AppDBSumRangeEnd
Sheets("Application Database").Select
Range("N4").Select
Set AppDBSumRangeStart = Application.ActiveCell
Do Until ActiveCell = ""
ActiveCell.Offset(1, 0).Select
Loop
ActiveCell.Offset(-1, 0).Select
Set AppDBSumRangeEnd = Application.ActiveCell
Dim AppDBYearRangeStart As Range
Dim AppDBYearRangeEnd As Range
Sheets("Application Database").Select
Range("AA4").Select
Set AppDBYearRangeStart = Application.ActiveCell
Do Until ActiveCell = ""
ActiveCell.Offset(1, 0).Select
Loop
ActiveCell.Offset(-1, 0).Select
Set AppDBYearRangeEnd = Application.ActiveCell
Dim AppDBTargetAreaRangeStart As Range
Dim AppDBTargetAreaRangeEnd As Range
Sheets("Application Database").Select
Range("D4").Select
Set AppDBTargetAreaRangeStart = Application.ActiveCell
Do Until ActiveCell = ""
ActiveCell.Offset(1, 0).Select
Loop
ActiveCell.Offset(-1, 0).Select
Set AppDBTargetAreaRangeEnd = Application.ActiveCell
Dim AppDBTypeRangeStart As Range
Dim AppDBTypeRangeEnd As Range
Sheets("Application Database").Select
Range("D4").Select
Set AppDBTypeRangeStart = Application.ActiveCell
Do Until ActiveCell = ""
ActiveCell.Offset(1, 0).Select
Loop
ActiveCell.Offset(-1, 0).Select
Set AppDBTypeRangeEnd = Application.ActiveCell
Sheets("Totals").Select
Range("C8").Select
'**This is the cell where I want the SUMIFs function to show the result.**
End Sub
***************************************
Any help is greatly appreciated!
Thanks in advanced!