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 | |
| 1111111 | 23 | |
| 2222222 | 43 | |
| 3333333 | 4 |
thank you in advance π
best regards
michal
3 Replies
- SaviaIron ContributorIs 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.
- TimBormCopper 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 Longlastrow = Cells(Rows.Count, "B").End(xlUp).Row
ActiveSheet.Range("B2:B" & lastrow).AdvancedFilter _
Action:=xlFilterCopy, _
CopyToRange:=ActiveSheet.Range("D2"), _
Unique:=True
End Sub- TimBormCopper 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