# Trending Sum Macro

#### pavanranjan

##### Board Regular
Hi Team,
Need help to create a macro for 12 month sliding to right for Sum their values

Yellow marked will be 12 months in a row which is available data
Blue marked
in the desired output post inserting three columns post city column. Grand total formula is also required

 Tending DSO Tending DSO Tending DSO 202103 202103 202102 202102 202102 202101 202101 202101 202100 202100 202100 Customer no Customer Name City Sales AR DSO Sales AR DSO Sales AR DSO Sales AR DSO Sales AR DSO 00123456 North Cansus NYC 400 360 27 100​ 90​ 27​ 100​ 90​ 27​ 100​ 90​ 27​ 100​ 90​ 27​ 00123457 Mount Cenai ABC 1000 900 27 250​ 225​ 27​ 250​ 225​ 27​ 250​ 225​ 27​ 250​ 225​ 27​ 00123459 Holy child ZBA 1600 1440 27 400​ 360​ 27​ 400​ 360​ 27​ 400​ 360​ 27​ 400​ 360​ 27​ Total 3000 2700 27 750 675 27 750 675 27 750 675 27 750 675 27

### Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

#### offthelip

##### Well-known Member
try this code:
VBA Code:
``````Sub test()
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
' load all the data to column R
inarr = Range(Cells(1, 1), Cells(lastrow, 18))
For i = 1 To 18
If inarr(2, i) = "Sales" Or inarr(2, i) = "AR" Then
tot = 0
For j = 3 To lastrow
tot = tot + inarr(j, i)
Next j
Range(Cells(lastrow + 1, i), Cells(lastrow + 1, i)) = tot
End If
If inarr(2, i) = "DSO" Then
Range(Cells(lastrow + 1, i), Cells(lastrow + 1, i)) = inarr(lastrow, i)
End If
Next i

End Sub``````

Replies
6
Views
198
Replies
1
Views
262
Replies
1
Views
338
Replies
15
Views
1K
Replies
6
Views
176

Threads
1,129,568
Messages
5,637,094
Members
416,957
Latest member
Brovashift

### 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

### 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