#### AbhishekJain

##### New Member
Hi!!

I am looking for a code which will add subtotals in column M,N,O, Q,R,S and W,X,Y.

First I am trying to sort the transactions in column Z..

'Sort as per Type of transaction
Dim Wb1 As Workbook
Dim ws1 As Worksheet

Range("A1:AF20000").Sort _

Sub ApplySubTotals()
Set ws1 = ThisWorkbook.Sheets("Purchase")
Range("Z1").Activate
Selection.Subtotal GroupBy:=26, Function:=xlSum, TotalList:=Array(13, 14, _
15, 17, 18, 19, 23, 24, 25), Replace:=True, PageBreaks:=False, SummaryBelowData _
:=True
End Sub

The code does not seem to work always.. Any suggestions to improve my codes?

### Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a \$25,000 loan, 5% annual interest, 60 month loan.
Welcome to the Board

Code:
``````Sub Abhis()
Dim ws As Worksheet
Set ws = ActiveSheet
ws.Sort.SortFields.Clear
ws.Sort.SortFields.Add ws.[z1], xlSortOnValues, xlAscending, , xlSortNormal
With ws.Sort
.SetRange Range("Z1:Z" & ws.Range("z" & Rows.count).End(xlUp).Row)
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlStroke
.Apply
End With
ws.[a1].Activate                ' reference cell at column A
Selection.Subtotal 1, xlSum, Array(13, 14, 15, 17, 18, 19, 23, 24, 25), True, False, xlSummaryBelow
End Sub``````

Replies
2
Views
426
Replies
3
Views
250
Replies
7
Views
374
Replies
3
Views
504
Replies
1
Views
277

1,196,078
Messages
6,013,301
Members
441,760
Latest member
Sharina

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

### Which adblocker are you using?

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

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