How to Use the VBA Sumifs with Multiple Criteria in the Same Column – 3 Steps

This is the sample dataset.

dataset vba sumifs multiple criteria in same column


Step 1 – Create a New Module in Visual Basic Window

  • Select Developer.
  • Choose Visual Basic.

Create new module

  • In the VBA window, select Insert.
  • Select Module.

A new module is created.

Read More: SUMIFS with Multiple Criteria in the Same Column


Step 2 – Enter the VBA Macro Code

  • Use the following code in the new module:
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:

  • creates a sub-procedure: Sumifs_same_column_multiple_criteria()
  • sets the value of Total to 0.
  • a For loop is used for the Total.
  • the criteria are set using the IF statement
  • n defines the row number.
  • the result is displayed in C13.

Step 3 – Run the VBA Macro to Apply Multiple Criteria in the Same Column

  • Select the icon shown below.

Run Write down vba for sumifs multiple criteria in same column

Excel will run the code and show the result.

Read More: How to Use SUMIFS with Multiple Criteria in the Same Column


Things to Remember

  • You can also press ALT+F11 to open the Visual Basic Window.
  • You can press F5 to run the code.

Download Practice Workbook

Download this workbook.


Related Articles


<< Go Back to Excel SUMIFS with Multiple Criteria | Excel SUMIFS Function | Excel Functions | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
Akib Bin Rashid
Akib Bin Rashid

AKIB BIN RASHID, a materials and metallurgical engineer, is passionate about delving into Excel and VBA programming. To him, programming is a valuable time-saving tool for managing data, files, and internet-related tasks. Proficient in MS Office, AutoCAD, Excel, and VBA, he goes beyond the fundamentals. Holding a B.Sc in Materials and Metallurgical Engineering from Bangladesh University of Engineering and Technology, MD AKIB has transitioned into a content development role. Specializing in creating technical content centred around Excel and... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo