How to Use VBA Sumifs with Multiple Criteria in Same Column

Get FREE Advanced Excel Exercises with Solutions!

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.

dataset vba sumifs multiple criteria in same column


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.

Create new module

  • 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

Write down vba for sumifs multiple criteria in same column

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).

Run Write down vba for sumifs multiple criteria in same column

  • Excel will run the code and show the result.

Read More: SUMIFS with Multiple Criteria in the Same Column


Similar Readings


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

Akib Bin Rashid
Akib Bin Rashid

Hi, this is MD Akib Bin Rashid. I completed my BSc in Engineering back in 2019. After that, I did an MBA. Then, I joined as an Excel and VBA Content Developer at SOFTEKO Digital. Being passionate about data analytics and finance, I will try to assist you with Excel

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo