Autosum

ravia2buri

New Member
Joined
Dec 12, 2017
Messages
1
Hi can anyone help me in getting sum in column. Automatic sum to come whenever unit name changes.


[TABLE="width: 495"]
<colgroup><col><col><col></colgroup><tbody>[TR]
[TD]Amount
[/TD]
[TD]Unit Name[/TD]
[TD]Sum
[/TD]
[/TR]
[TR]
[TD] 10,228
[/TD]
[TD]A
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD] 10,228
[/TD]
[TD]A
[/TD]
[TD]
[/TD]
[/TR]
[TR]
[TD] 9,318[/TD]
[TD]B
[/TD]
[TD]
[/TD]
[/TR]
[TR]
[TD] 1,432[/TD]
[TD]B
[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD] 10,652[/TD]
[TD]B
[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD] 12,479[/TD]
[TD]D
[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD] 400[/TD]
[TD]D
[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD] 10,072
[/TD]
[TD]D
[/TD]
[TD] [/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Excel 2010[TABLE="class: grid, width: 400"]
<colgroup><col><col><col><col></colgroup><tbody>[TR="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD]Amount[/TD]
[TD]Unit Name[/TD]
[TD]Sum[/TD]
[/TR]
[TR]
[TD="align: center"]2[/TD]
[TD="align: right"]10,228[/TD]
[TD]A[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: center"]3[/TD]
[TD="align: right"]10,228[/TD]
[TD]A[/TD]
[TD="align: right"]20,456.00[/TD]
[/TR]
[TR]
[TD="align: center"]4[/TD]
[TD="align: right"]9,318[/TD]
[TD]B[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: center"]5[/TD]
[TD="align: right"]1,432[/TD]
[TD]B[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: center"]6[/TD]
[TD="align: right"]10,652[/TD]
[TD]B[/TD]
[TD="align: right"]21,402.00[/TD]
[/TR]
[TR]
[TD="align: center"]7[/TD]
[TD="align: right"]12,479[/TD]
[TD]D[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: center"]8[/TD]
[TD="align: right"]400[/TD]
[TD]D[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: center"]9[/TD]
[TD="align: right"]10,072[/TD]
[TD]D[/TD]
[TD="align: right"]22,951.00[/TD]
[/TR]
</tbody>[/TABLE]
Sheet4

Copy the formula down
[TABLE="width: 85%"]
<tbody>[TR]
[TD]Worksheet Formulas[TABLE="width: 100%"]
<thead>[TR="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]
[TH="width: 10"]Cell[/TH]
[TH="align: left"]Formula[/TH]
[/TR]
</thead><tbody>[TR]
[TH="width: 10, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]C2[/TH]
[TD="align: left"]=IF(B2=B3,"",SUMIF($B$2:B2,$B$2:B2,$A$2:A2))[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
ravia2buri,

Welcome to the MrExcel forum.

Here is a macro solution for you to consider, that is based on your flat text display.

Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

1. Copy the below code
2. Open your NEW workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.

Code:
Sub SumUniques()
' hiker95, 12/12/2017, ME1034963
Application.ScreenUpdating = False
Dim r As Long, lr As Long, n As Long, i As Long, tot As Long
With ActiveSheet
  lr = .Cells(Rows.Count, 2).End(xlUp).Row
  For r = 2 To lr
    n = Application.CountIf(.Columns(2), .Cells(r, 2).Value)
    If n = 1 Then
      .Range("C" & r).Value = .Range("A" & r).Value
    ElseIf n > 1 Then
      tot = 0
      For i = r To r + n - 1
        tot = tot + .Range("A" & i).Value
      Next i
      With .Range("C" & r + n - 1)
        .Value = tot
        .NumberFormat = "#,##0"
      End With
    End If
    r = r + n - 1
  Next r
End With
Application.ScreenUpdating = True
End Sub

Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm, and, answer the "do you want to enable macros" question as "yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.

Then run the SumUniques macro.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top