Results 1 to 5 of 5

Thread: [RESOLVED] Sorting Excel 2007 using VB 2010

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2010
    Location
    NYC
    Posts
    14

    Resolved [RESOLVED] Sorting Excel 2007 using VB 2010

    I'm trying to sort a range in excel 2007, copy it and export it to another workbook. I can get as far as selecting the range but, I get lost after that...I have searched a lot of threads but, just can't seem to find one that give me an exact answer. Any help would be appreciated.

    Mike

  2. #2
    Hyperactive Member
    Join Date
    Oct 2010
    Location
    Indiana
    Posts
    457

    Re: Sorting Excel 2007 using VB 2010

    Why don't you try to use the Macro Recorder in Excel and look at the codes in VBA. Might help get you started.

  3. #3
    Frenzied Member MattP's Avatar
    Join Date
    Dec 2008
    Location
    WY
    Posts
    1,227

    Re: Sorting Excel 2007 using VB 2010

    Here's code I had laying around to AutoFilter and Sort and Excel.Range

    Code:
            Dim Range As Excel.Range
            Range = ws.Range("A1:G50")
            Range.AutoFilter(1, , Excel.XlAutoFilterOperator.xlAnd, , True)
            Range.Sort(Key1:=Range.Columns(1), Order1:=Excel.XlSortOrder.xlAscending, _
                       Orientation:=Excel.XlSortOrientation.xlSortColumns, _
                       Header:=Excel.XlYesNoGuess.xlNo, _
                       SortMethod:=Excel.XlSortMethod.xlPinYin, _
                       DataOption1:=Excel.XlSortDataOption.xlSortNormal, _
                       DataOption2:=Excel.XlSortDataOption.xlSortNormal, _
                       DataOption3:=Excel.XlSortDataOption.xlSortNormal)

  4. #4

    Thread Starter
    New Member
    Join Date
    Nov 2010
    Location
    NYC
    Posts
    14

    Re: Sorting Excel 2007 using VB 2010

    Thank you Matt. Your code works for me. I really appreciate it.

    Mike

  5. #5
    New Member
    Join Date
    Apr 2011
    Posts
    1

    Re: [RESOLVED] Sorting Excel 2007 using VB 2010

    This code works great, but what if one column that I want to sort by is a date? Currently it's reading it as a string and then sorting by day then month. Any solutions?

Posting Permissions

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



Click Here to Expand Forum to Full Width