Forum Discussion
TimBorm
Feb 09, 2020Copper Contributor
VBA sumif code
Hi All, please help with macro that will look for the same value in column and then sum value from another column. ex. id qyt sum 1111111 14 2222222 56 3333333 534 ...
Savia
Feb 09, 2020Iron Contributor
Is there some reason this needs to be done in VBA? Either an actual SUMIF function or a PivotTable would be much, much easier and more reliable.
TimBorm
Feb 09, 2020Copper Contributor
For next purpose it need to be done in VBA, but i think that i found the easiest way:
Option Explicit
Sub CreateUniqueList()
Dim lastrow As Long
lastrow = Cells(Rows.Count, "B").End(xlUp).Row
ActiveSheet.Range("B2:B" & lastrow).AdvancedFilter _
Action:=xlFilterCopy, _
CopyToRange:=ActiveSheet.Range("D2"), _
Unique:=True
End Sub
- TimBormFeb 09, 2020Copper Contributormy mistake :D:D this one:
Sub sumifFunction()
Range(“G2”) = “A”
Range(“H2”) = Application.WorksheetFunction.SumIf(Range(“A2:B8”), “A”, Range(“B2:B8”))
End Sub