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

Sort Statement

Zach

Member
Ladies/Gentlemen
I need to get a sort statement in here. It pulls all the data and does all the subtotaling I want but I need it to sort first. I forgot that part and need column "G" to sort before it subtotals.

Any suggestions?

Code:
'Filter file
 CVT.Select
  CVT.Range(Cells(1, 1), "K" & lLast).AutoFilter Field:=2, Criteria1:="Phoenix"
  CVT.Range(Cells(1, 1), "K" & lLast).SpecialCells(xlCellTypeVisible).Copy
  MTab.Range("A1").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
  :=False, Transpose:=False
  Application.CutCopyMode = False
  With MTab
  .Select
  .Cells.Select
  .Cells.EntireColumn.AutoFit
  lLast = .Range("A" & Rows.Count).End(xlUp).Row
  .Sort.SortFields.Add Key:=Range(.Cells(1, 1), "G" & lLast) _
    , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
  .Range(.Cells(1, 1), "K" & lLast).Subtotal GroupBy:=7, Function:=xlSum, TotalList:=Array(11), _
  Replace:=True, PageBreaks:=False, SummaryBelowData:=True
  lLast = .Range("G" & Rows.Count).End(xlUp).Row
  With .Range(.Cells(1, 1), "K" & lLast).Borders
  .LineStyle = xlContinuous
  .ColorIndex = 0
  .TintAndShade = 0
  .Weight = xlThin
  End With

I'm attaching the file as well.

Thanks
 

Attachments

  • Denver VPO Reasons Report Details - 8-23-15 to 8-29-15.xlsm
    239.7 KB · Views: 1
Hi ,

See the attached file.

Narayan
 

Attachments

  • Copy of Denver VPO Reasons Report Details - 8-23-15 to 8-29-15.xlsm
    235.5 KB · Views: 1
Is that a way to get an Input box to pop up and allow me to call out the division I want the Macro to run on? Input/message boxes are something I've never worked with before.
 

Attachments

  • Denver VPO Reasons Report Details - 8-23-15 to 8-29-15.xlsm
    234.8 KB · Views: 3
Something like this, and replace "Phoenix" with myDiv in NARAYANK991's code.

Code:
Dim myDiv As String
myDiv = InputBox("Type Division Name")
If Len(myDiv) = 0 Then
    MsgBox "Please Enter a Division Name", vbCritical
    Exit Sub
    Else
End If

However, InputBox is very limited and isn't very user friendly. As you will need to code to catch if user typed in something that does not exist in list of divisions.

Instead, I'd recommend using another sheet to house dropdown list or some other type of list to choose division and use command button to run the macro.
 
Here's quick sample using command button to extract unique Division names and button to run NARAYANK991's code with myDiv set to active cell value.
 

Attachments

  • Denver VPO Reasons Report Details - 8-23-15 to 8-29-15 (1).xlsm
    222.1 KB · Views: 3
Back
Top