+ Reply to Thread
Results 1 to 3 of 3

Sort problems with macro

  1. #1
    Registered User
    Join Date
    05-17-2013
    Location
    Seattle, WA.
    MS-Off Ver
    Excel 2007
    Posts
    4

    Question Sort problems with macro

    Hi all!

    I am trying to sort all rows of a work sheet with a header by one header name. Below is a sample of my data. I bring it in from a CSV file. Below that is the code to do the sort however, when I run the macro it will not sort. I used the macro recorder to do the code as I haven't been in VB for years. I will want to use this in several workbooks that have varying number of rows but all have the same format.

    05 2013
    Class 4 Ship To Item Description Extended Description 2 CompFcst
    200 #N/A 132002 UL HAL FLTCH #1 FRESH 5# RDM WT 0
    280 31 ABC123 SOCK SAL PTN PBO 6OZ VP 10/3# 122000
    280 32 ABC456 SOCK PTN PBO 6OZ VP 10/3# 0
    280 33 ABC789 SOCK PTN PBO 6OZ VP 10/3# 25000
    280 34 ABCABC SOCK PTN PBO 6OZ VP 10/3# 3000

    Sub Macro10()
    '
    ' Macro10 Macro
    '

    '
    Rows("2:2").Select
    Range(Selection, Selection.End(xlDown)).Select
    ActiveWorkbook.Worksheets("Sheet1 (7)").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Sheet1 (7)").Sort.SortFields.Add Key:=Range( _
    "B3:B106"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
    xlSortNormal
    With ActiveWorkbook.Worksheets("Sheet1 (7)").Sort
    .SetRange Range("A3:AO106")
    .Header = xlYes
    .MatchCase = False
    .Orientation = xlTopToBottom
    .SortMethod = xlPinYin
    .Apply
    End With
    End Sub

    Thank you!!!

    Tanya

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,375

    Re: Sort problems with macro

    Please post a sample workbook.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    05-17-2013
    Location
    Seattle, WA.
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Sort problems with macro

    I have attached both the macro I'm working on and the unformatted data file.

    Thanks!

    Tanya
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1