Attribute VB_Name = "Module1" Sub Forex() Attribute Forex.VB_ProcData.VB_Invoke_Func = " \n14" ' ' Forex Macro ' ' recCount = Range("O65536").End(xlUp).Row Columns("O:O").EntireColumn.Insert Columns("O:O").EntireColumn.Insert Range("O5").Select ActiveCell.FormulaR1C1 = "Pip" Range("P5").Select ActiveCell.FormulaR1C1 = "System" Range("O6").Select ActiveCell.Formula = "=IF(AND(G6<20,D6=""buy""),(K6-G6)*10000,IF(AND(G6<20,D6=""sell""),( G6-K6)*10000,IF(AND(G6>20,D6=""buy""),(K6-G6)*100,(G6-K6)*100)))" Range("P6").Select ActiveCell.Formula = "=IF(ISNUMBER(SEARCH(""ltg"",Q6)),""ltg"",IF(ISNUMBER(SEARCH(""ftl"",Q6)),""ftl"",IF(ISNUMBER(SEARCH(""firepips"",Q6)),""firepips"",IF(ISNUMBER(SEARCH(""cm"",Q6)),""cm"",IF(ISNUMBER(SEARCH(""PipTurbo"",Q6)),""PipTurbo"",IF(ISNUMBER(SEARCH(""_515_"",Q6)),""TriggerFx"",IF(ISNUMBER(SEARCH(""mm"",Q6)),""mm"",IF(ISNUMBER(SEARCH(""fxpt"",Q6)),""fxpt"",""other""))))))))" Range("O6:P6").Select Selection.AutoFill Destination:=Range("O6:P" & recCount), Type:=xlFillDefault Range("O6:P" & recCount).Select Rows("5:" & recCount).Select Range("A" & recCount).Activate ActiveWorkbook.Worksheets("Polina Khoroshko_rep").Sort.SortFields.Clear ActiveWorkbook.Worksheets("Polina Khoroshko_rep").Sort.SortFields.Add Key:= _ Range("P6:P" & recCount), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _ :=xlSortNormal ActiveWorkbook.Worksheets("Polina Khoroshko_rep").Sort.SortFields.Add Key:= _ Range("F6:F" & recCount), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _ :=xlSortNormal With ActiveWorkbook.Worksheets("Polina Khoroshko_rep").Sort .SetRange Range("A5:Q" & recCount) .Header = xlYes .MatchCase = False .Orientation = xlTopToBottom .SortMethod = xlPinYin .Apply End With Selection.Subtotal GroupBy:=16, Function:=xlSum, TotalList:=Array(14, 15) _ , Replace:=True, PageBreaks:=False, SummaryBelowData:=True recCount = Range("O65536").End(xlUp).Row Rows("5:" & recCount).Select Range("A" & recCount).Activate Selection.Subtotal GroupBy:=6, Function:=xlSum, TotalList:=Array(14, 15), _ Replace:=False, PageBreaks:=False, SummaryBelowData:=True ActiveSheet.Outline.ShowLevels RowLevels:=2 Columns("P:P").ColumnWidth = 20 Columns("F:F").ColumnWidth = 20 End Sub