Have a Question?

If you have any question you can ask below or enter what you are looking for!



SumIf through VBA

Hi Mates

I am trying to use sumif function through VBA to add range with specified criteria. where "D2" is the criteria cell and "E2" is resultant
But code raising error of Typemismatch in the below highlighted statement

Public Sub total()
Dim Tot_sheet2 As Worksheet
Set Tot_sheet2 = Sheets(2)
Tot_sheet2.Activate
Dim mon As String
mon = Tot_sheet2.Range("d2").Value
Tot_sheet2.Range("e2").Value = Application.SumIf(Range("a2:a13"), "" * "&mon&" * "", Range("b2:b13"))
End Sub

Please help me out

  Deepak Sharma

Your code seems correct just you need to improve your sumif criteria. Rest all are good.

Please try below code to solve your purpose.

Public Sub total()
Dim Tot_sheet2 As Worksheet
Set Tot_sheet2 = Sheets(2)
Tot_sheet2.Activate
Dim mon As String
mon = Tot_sheet2.Range("d2").Value
Tot_sheet2.Range("e2").Value = WorksheetFunction.SumIf(Range("a2:a13"), "*" & mon & "*", Range("b2:b13"))
End Sub

Thanks,

  Devbrat Tripathi       23 Aug 2016       0       0     

Post Your Answers:

Please use the CODE HIGHLIGHT Button to format/highlight your codes if any