Excel is the most widely used tool for dealing with massive datasets. We can perform myriads of tasks of multiple dimensions in Excel. In this article, I will show you how to use VBA Sumifs with multiple criteria in the same column.
Use VBA Sumifs with Multiple Criteria in Same Column: 3 Easy Steps
This is the dataset for today’s article. There are some orders with the Price. I will calculate the price if the product is Mobile or AC. The SUMIFS function is useful here. However, I will illustrate how to use Sumifs using VBA macro here.
Step 1: Create New Module in Visual Basic Window
The first step is to create a new module.
- First of all, go to the Developer.
- Then, select Visual Basic.
- A VBA window will appear. Go to the Insert.
- After that, select Module.
- Excel will create a new module.
Read More: Exclude Multiple Criteria in Same Column with SUMIFS Function
Step 2: Write Down VBA Macro Code
The next step is to write down the VBA code. For this,
- Go to the new module and write down the following code
Sub Sumifs_same_column_multiple_criteria()
Total = 0
'Apply For loop
For n = 5 To 11
If Range("C" & n) = "Mobile" Or Range("C" & n) = "AC" Then
Total = Total + Range("D" & n)
End If
Next n
'Show Result
Range("C13") = Total
End Sub
Code Breakdown:
- First of all, I have created a sub-procedure Sumifs_same_column_multiple_criteria()
- Then, I set the value for Total to be 0.
- After that, I applied a For loop for the Total.
- Then, I set the criteria using the IF statement
- n defines the row number here.
- Finally, I showed the result in C13.
Read More: Excel SUMIFS with Multiple Sum Ranges and Multiple Criteria
Step 3: Run VBA Macro to Apply Multiple Criteria in Same Column
Finally, I will run the VBA macro. To do so,
- Select the icon (see the image below).
- Excel will run the code and show the result.
Read More: SUMIFS with Multiple Criteria in the Same Column
Similar Readings
- Excel SUMIFS with Multiple Vertical and Horizontal Criteria
- How to Apply SUMIFS with Multiple Criteria in Different Columns
- SUMIFS with Multiple Criteria Along Column and Row in Excel
Things to Remember
- You can press ALT+F11 to bring the Visual Basic Window.
- You can press F5 to run the code.
Download Practice Workbook
Download this workbook and practice while going through the article.
Conclusion
In this article, I have explained how to use VBA Sumifs with multiple criteria in the same column. I hope it helps everyone. If you have any suggestions, ideas, or feedback, please feel free to comment below.
Related Articles
- How to Use SUMIFS When Cells Are Not Equal to Multiple Text
- Excel SUMIFS Not Equal to Multiple Criteria
- How to Use SUMIFS Function with Wildcard in Excel
- SUMIFS with INDEX-MATCH Formula Including Multiple Criteria
- How to Apply SUMIFS with INDEX MATCH for Multiple Columns and Rows
- How to Use SUMIFS Function with Multiple Sheets in Excel
- [Fixed]: SUMIFS Not Working with Multiple Criteria