• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Recorded macro

spmurphy_no

New Member
can this recorded macro be shorter? thank You.

>>> use code - tags <<<
Code:
Sub Sales_tax()
'
' Sales_tax Macro
'

'
    Columns("D:F").Select
    Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    Columns("C:C").Select
    Selection.TextToColumns Destination:=Range("C1"), DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
        Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar _
        :="<", FieldInfo:=Array(Array(1, 1), Array(2, 1)), TrailingMinusNumbers:=True
    Columns("D:D").Select
    Selection.Replace What:="br>", Replacement:="", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False, FormulaVersion:=xlReplaceFormula2
    Selection.TextToColumns Destination:=Range("D1"), DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
        Semicolon:=False, Comma:=True, Space:=False, Other:=False, OtherChar _
        :="<", FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3, 1)), _
        TrailingMinusNumbers:=True
    ActiveWindow.ScrollColumn = 2
    ActiveWindow.ScrollColumn = 3
    ActiveWindow.ScrollColumn = 2
    ActiveWindow.ScrollColumn = 1
    Range("D1").Select
    ActiveCell.FormulaR1C1 = "Client city"
    Range("E1").Select
    ActiveCell.FormulaR1C1 = "Client  State"
    Range("F1").Select
    ActiveCell.FormulaR1C1 = "Client Zip ode"
    Range("F2").Select
    Sheets.Add
    ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        "report1597179135841!R1C1:R138C18", Version:=6).CreatePivotTable _
        TableDestination:="Sheet1!R3C1", TableName:="PivotTable1", DefaultVersion _
        :=6
    Sheets("Sheet1").Select
    Cells(3, 1).Select
    With ActiveSheet.PivotTables("PivotTable1")
        .ColumnGrand = True
        .HasAutoFormat = True
        .DisplayErrorString = False
        .DisplayNullString = True
        .EnableDrilldown = True
        .ErrorString = ""
        .MergeLabels = False
        .NullString = ""
        .PageFieldOrder = 2
        .PageFieldWrapCount = 0
        .PreserveFormatting = True
        .RowGrand = True
        .SaveData = True
        .PrintTitles = False
        .RepeatItemsOnEachPrintedPage = True
        .TotalsAnnotation = False
        .CompactRowIndent = 1
        .InGridDropZones = False
        .DisplayFieldCaptions = True
        .DisplayMemberPropertyTooltips = False
        .DisplayContextTooltips = True
        .ShowDrillIndicators = True
        .PrintDrillIndicators = False
        .AllowMultipleFilters = False
        .SortUsingCustomLists = True
        .FieldListSortAscending = False
        .ShowValuesRow = False
        .CalculatedMembersInFilters = False
        .RowAxisLayout xlCompactRow
    End With
    With ActiveSheet.PivotTables("PivotTable1").PivotCache
        .RefreshOnFileOpen = False
        .MissingItemsLimit = xlMissingItemsDefault
    End With
    ActiveSheet.PivotTables("PivotTable1").RepeatAllLabels xlRepeatLabels
    With ActiveSheet.PivotTables("PivotTable1").PivotFields("Client city")
        .Orientation = xlRowField
        .Position = 1
    End With
    ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
        "PivotTable1").PivotFields("Net Fee Earned"), "Sum of Net Fee Earned", xlSum
    With ActiveSheet.PivotTables("PivotTable1").PivotFields("Sum of Net Fee Earned" _
        )
        .NumberFormat = "#,##0.00"
    End With
End Sub
 
Last edited by a moderator:
I can't test this easily but you can try:
Code:
Sub Sales_tax()
Columns("D:F").Insert
Columns("C:C").TextToColumns Destination:=Range("C1"), DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar:="<", FieldInfo:=Array(Array(1, 1), Array(2, 1)), TrailingMinusNumbers:=True
Columns("D:D").Replace What:="br>", Replacement:="", LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False, FormulaVersion:=xlReplaceFormula2
Columns("D:D").TextToColumns Destination:=Range("D1"), DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False, Comma:=True, Space:=False, Other:=False, OtherChar:="<", FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3, 1)), TrailingMinusNumbers:=True
Range("D1:F1").Value = Array("Client city", "Client  State", "Client Zip Code")
Set NewSht = Sheets.Add
Set PT = ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:="report1597179135841!R1C1:R138C18").CreatePivotTable(TableDestination:=NewSht.Range("A3"))
With PT
'  .ColumnGrand = True
'  .HasAutoFormat = True
'  .DisplayErrorString = False
'  .DisplayNullString = True
'  .EnableDrilldown = True
'  .ErrorString = ""
'  .MergeLabels = False
'  .NullString = ""
'  .PageFieldOrder = 2
'  .PageFieldWrapCount = 0
'  .PreserveFormatting = True
'  .RowGrand = True
'  .SaveData = True
'  .PrintTitles = False
'  .RepeatItemsOnEachPrintedPage = True
'  .TotalsAnnotation = False
'  .CompactRowIndent = 1
'  .InGridDropZones = False
'  .DisplayFieldCaptions = True
'  .DisplayMemberPropertyTooltips = False
'  .DisplayContextTooltips = True
'  .ShowDrillIndicators = True
'  .PrintDrillIndicators = False
'  .AllowMultipleFilters = False
'  .SortUsingCustomLists = True
'  .FieldListSortAscending = False
'  .ShowValuesRow = False
'  .CalculatedMembersInFilters = False
'  .RowAxisLayout xlCompactRow
'  With .PivotCache
'    .RefreshOnFileOpen = False
'    .MissingItemsLimit = xlMissingItemsDefault
'  End With
  .RepeatAllLabels xlRepeatLabels
  With .PivotFields("Client city")
    .Orientation = xlRowField
    .Position = 1
  End With
  .AddDataField .PivotFields("Net Fee Earned"), "Sum of Net Fee Earned", xlSum
  .PivotFields("Sum of Net Fee Earned").NumberFormat = "#,##0.00"
End With
End Sub
There's a whole raft of commented out lines which I think are the defaults; if something is obviously wrong you can pick and choose which to reintroduce.
 
Back
Top