How to sum a column in excel vba free#
Kutools for Excel: with more than 300 handy Excel add-ins, free to try with no limitation in 30 days. Here, I introduce the handy tool - Kutools for Excel for you, its Advanced Combine Rows also can quickly do a favor to solve this problem.
How to sum a column in excel vba code#
Note: If you want to use this code, you’d better make a copy of the file to avoid destroying the data, and this code is only applied to two columns. And then click OK, the duplicate rows have been combined and the values are added up. Then press F5 key to run this code, and you need to select the range that you want to consolidate in the popped out prompt box. WorkRng.Range("A1").Resize(Dic.Count, 1) = (Dic.keys) Set Dic = CreateObject("Scripting.Dictionary")ĭic(arr(i, 1)) = Dic(arr(i, 1)) + arr(i, 2) Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8) VBA code: Combine duplicate rows and sum the values Sub CombineRows() Click Insert > Module, and paste the following code in the Module Window. Hold down the ALT + F11 keys, then it opens the Microsoft Visual Basic for Applications window.Ģ. The following VBA code also can help you consolidate duplicate rows in the worksheet, but at the same time, the original data will be destroyed, you need to backup a copy of the data.ġ. Kutools for Excel's Advanced Combibe Rows helps you to combine multiple duplicate rows into one record based on a key column, and it also can apply some calculations such as sum, average, count and so on for other columns.
![how to sum a column in excel vba how to sum a column in excel vba](https://www.exceldome.com/wp-content/uploads/2018/07/Sum-values-by-day.png)
Note: If the range do not have the header row, you need uncheck Top row from the Use labels in option.Ĭombine duplicate rows and sum / average corresponding values in another column After finishing the settings, click OK, and the duplicates are combined and summed.