Results 1 to 11 of 11

I have a sort macro. How to add script to preselect rows to sort based on column value?

Threaded View

Jasonhouse I have a sort macro. How to... 03-05-2014, 07:37 PM
protonLeah Re: I have a sort macro. How... 03-05-2014, 10:18 PM
Jasonhouse Re: I have a sort macro. How... 03-06-2014, 02:05 PM
protonLeah Re: I have a sort macro. How... 03-06-2014, 11:03 PM
Jasonhouse Re: I have a sort macro. How... 03-07-2014, 10:37 AM
protonLeah Re: I have a sort macro. How... 03-07-2014, 09:33 PM
Jasonhouse Re: I have a sort macro. How... 03-08-2014, 11:26 PM
Jasonhouse Re: I have a sort macro. How... 03-08-2014, 11:26 PM
Jasonhouse Re: I have a sort macro. How... 03-09-2014, 12:38 AM
Jasonhouse Re: I have a sort macro. How... 03-09-2014, 12:45 AM
protonLeah Re: I have a sort macro. How... 03-09-2014, 02:25 AM
  1. #1
    Registered User
    Join Date
    03-05-2014
    Location
    Tampa, FL
    MS-Off Ver
    Excel 2010
    Posts
    28

    I have a sort macro. How to add script to preselect rows to sort based on column value?

    I have a macro which performs a sort for me.

    I have it set up to perform the sort on whatever rows are preselected by the user.

    I would like to have the macro preselect the rows to sort for me, based on whether there is any value in a certain column (it will always be the same column, 'G'). All cells in column G presently contain either nothing, or a number between 1 and 20. I prefer the macro select rows based on whether there is any value in cells in column G at all, as I may add additional numbers later.

    EDIT: Oh, and if it helps, all of the rows with a value in them will always be contiguous to one another. All of the blank cells are at the top and bottom (but those exact locations vary.)

    This is what I'm using that I want to add on to.
    Sub Sort()
    '
    ' Sort Macro
    ' Sort based on column 'G'
    '
    ' Keyboard Shortcut: Ctrl+m
    '
        ActiveWorkbook.Worksheets(ActiveSheet.Name).Sort.SortFields.Clear
        ActiveWorkbook.Worksheets(ActiveSheet.Name).Sort.SortFields.Add Key:=Selection.Columns(7), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
            xlSortNormal
        ActiveWorkbook.Worksheets(ActiveSheet.Name).Sort.SortFields.Add Key:=Selection.Columns(4), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
            xlSortNormal
        ActiveWorkbook.Worksheets(ActiveSheet.Name).Sort.SortFields.Add Key:=Selection.Columns(3), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
            xlSortNormal
        With ActiveWorkbook.Worksheets(ActiveSheet.Name).Sort
            .SetRange Selection
            .Header = xlGuess
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
        Selection.Rows.AutoFit
    End Sub
    Thank you for your help. I'm a total rookie at this VBA stuff. But at my small firm, I'm the default "techie" by virtue of everyone else being even more clueless than I am. lol
    Last edited by Leith Ross; 03-05-2014 at 09:59 PM. Reason: Changed Quote tags to Code Tags

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Macro for sort rows after value in certain column
    By abjac in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-26-2014, 06:47 AM
  2. script for sort z to A in a column
    By saranyabi in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-05-2013, 11:40 AM
  3. Copying rows from other sheets, and sort them based on a priority column
    By BKevinT in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-26-2010, 11:59 AM
  4. [SOLVED] [SOLVED] need help righting script to sort rows alphabetically then seperate them to
    By Kamachi923@gmail.com in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-15-2005, 12:10 PM
  5. [SOLVED] need help righting script to sort rows alphabetically then seperate them to line up
    By Kamachi923@gmail.com in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 11-14-2005, 09:25 PM

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