Results 1 to 3 of 3
  1. #1
    samthomasny is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2011
    Posts
    7

    VB Dynamic Range Sorting

    I badly need some help with this macro


    Data is from Col A to H
    Row 1 is the headers
    And I want it sorted by col A
    The script below is working perfect; but my problem is that it is a dynamic range
    Hence I want to replace that "A1:H12" with something else.
    My thought was that I already have a selection of the entire data range when I did -
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select

    Can someone please help me?

    Sub aaa()

    Range("A1").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    ActiveWorkbook.Worksheets("Sheet1").Sort.SortField s.Clear
    ActiveWorkbook.Worksheets("Sheet1").Sort.SortField s.Add Key:=Range("A1") _
    , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Sheet1").Sort
    .SetRange Range("A1:H12")
    .Header = xlYes
    .MatchCase = False
    .Orientation = xlTopToBottom
    .SortMethod = xlPinYin
    .Apply
    End With
    Range("A1").Select
    End Sub

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,970
    Does this help http://www.excely.com/excel-vba/how-...election.shtml

    Try:
    Set SelRange = Selection
    With ActiveWorkbook.Worksheets("Sheet1").Sort
    .SetRange SelRange
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    samthomasny is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2011
    Posts
    7
    Worked perfect. Thanks, appreciate the timely help

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Dynamic crosstab report sorting headings & dlookup
    By chrisangk in forum Programming
    Replies: 9
    Last Post: 01-14-2013, 02:37 PM
  2. Sorting Query through Forum for range
    By dbalilti in forum Access
    Replies: 22
    Last Post: 08-14-2012, 11:13 AM
  3. Replies: 11
    Last Post: 01-12-2012, 07:55 PM
  4. Dynamic Form, Dynamic labels/ captions?
    By JFo in forum Programming
    Replies: 15
    Last Post: 10-12-2011, 08:33 PM
  5. DSum with Dynamic Range
    By Kimbertha in forum Queries
    Replies: 15
    Last Post: 11-05-2010, 11:47 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums