Results 1 to 4 of 4

Sort data in VBA in order of A-Z

This is a discussion on Sort data in VBA in order of A-Z within the Excel Questions forums, part of the Question Forums category; I would like to automaticly sort my data by the following: Sort by column B Sort based on values In ...

  1. #1
    New Member
    Join Date
    Dec 2009
    Posts
    12

    Default Sort data in VBA in order of A-Z

    I would like to automaticly sort my data by the following:

    Sort by column B
    Sort based on values
    In order of A-Z
    (only on sheets "master" and "updates")

    can i do this in VBA to make it automatic in my excel file?

    I copy/paste data throughout the day into sheets in this workbook and would like it to always be sorted for me.

    Also - the sheets master and updates are deleted throughout the day and re-created - so hopefully vba wont #ref all the ref's to the sheets as they will be back later?

  2. #2
    Board Regular
    Join Date
    May 2009
    Location
    Texas, USA
    Posts
    1,290

    Default Re: Sort data in VBA in order of A-Z

    You can create vba procedures to sort your data. Next time you do a regular short of your data turn on RecordMacro and then copy the generated code to your vba module. Need more information to give any specifics
    Bill
    Use Option Explicit to avoid chasing code.

  3. #3
    New Member
    Join Date
    Dec 2009
    Posts
    12

    Default Re: Sort data in VBA in order of A-Z

    Woah that is cool!

    Code:
        ActiveWorkbook.Worksheets("updates").Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("updates").Sort.SortFields.Add Key:=Range("B2:B292" _
            ), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        With ActiveWorkbook.Worksheets("updates").Sort
            .SetRange Range("A1:P292")
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
             End With
    i would like that applied to two sheets in my book, where would i put it so its always sorted instead of assigning a button to it?

  4. #4
    Board Regular
    Join Date
    May 2009
    Location
    Texas, USA
    Posts
    1,290

    Default Re: Sort data in VBA in order of A-Z

    You could use one of the Worksheet Event procedures to automatically short.

    If youe use the Worksheet_Change event then everytime there is a chage of data on teh work sheet the sort procedure would run. YOu can limit it to run when only specified cells change dfata.

    Need to know what triggers when the data is ready to be sorted.
    Bill
    Use Option Explicit to avoid chasing code.

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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


DMCA.com