Consulting

Results 1 to 12 of 12

Thread: Solved: auto descending order using macro

  1. #1

    Solved: auto descending order using macro

    please help me...i'm totaly zero knowledge in VBA...

    i have running data from others program and then i extract to excel program..
    my problem is...
    1. the data not in descending order..
    i need to do auto descending order using macro...already try copy and
    paste the program but cannot run....
    2. the running data is at sheet 1 and i plan to do the auto descending order
    at sheet two.

    can someone help me...already stuck about one week for this problem...
    here i attach sample worksheet for your to add the vba...

    thanks
    muzammel

  2. #2
    VBAX Regular
    Joined
    Jan 2009
    Posts
    93
    Location

    Smile

    if me is not wrong with target

  3. #3
    thank for the reply...i will try first...any result i will post...thank you very much

  4. #4
    hardlife...the worksheet is running...thank you... I
    I have questions..
    - if i need to add another data for another column..how should i do...

    thanks...

  5. #5
    VBAX Regular
    Joined
    Jan 2009
    Posts
    93
    Location

    Smile

    muzammel... happy me understood :-) me is happy it works

    - what data do You need to add?

    - best should be to show input and desired output in attachment

    now it copies all data from first sheet (without limit)
    and paste all data to second sheet (than sorts data in column B descendig)

    Good Night for now, Pavel

  6. #6
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    This gives you the option to set the sort column

    [VBA]Sub sortdata()
    Dim Col
    Col = InputBox("Column to sort by?")
    Sheets("running data").Cells.Copy Sheets("auto desecending").Range("A1")
    With ActiveWorkbook.Worksheets("auto desecending")
    .Cells.Sort Key1:=.Cells(2, Col), Order1:=xlDescending, Header:=xlGuess, _
    OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
    End With
    End Sub
    [/VBA]

    Pavel,
    Good working code. Try though, to trim out "Select" which simplifies and speeds up the execution of your code.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  7. #7

    actual format in excel

    hai...

    here i attach the exactly format that i need to use...
    can someone add the program since i'm totaly blind in the programming language...

    at "running data" sheet is data i extract from others program..
    so i need another sheet for data after sort with descending order...

    thanks....

  8. #8
    Quote Originally Posted by mdmackillop
    This gives you the option to set the sort column

    [vba]Sub sortdata()
    Dim Col
    Col = InputBox("Column to sort by?")
    Sheets("running data").Cells.Copy Sheets("auto desecending").Range("A1")
    With ActiveWorkbook.Worksheets("auto desecending")
    .Cells.Sort Key1:=.Cells(2, Col), Order1:=xlDescending, Header:=xlGuess, _
    OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
    End With
    End Sub
    [/vba]
    Pavel,
    Good working code. Try though, to trim out "Select" which simplifies and speeds up the execution of your code.

    If i need to use this program...what should i do...just copy all the above program and then past at VB..
    can u assist me...thanks in advance

  9. #9
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Try this
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  10. #10
    Quote Originally Posted by mdmackillop
    Try this
    Thank for your help...i will try first and let you know...
    thank for your help

  11. #11
    hai...after test the latest version from mdmackillop...the worksheet is running...
    thank for every one for helping me...

    i have another question...how to mark this thread with "solved"...

    found the "solved" button...

  12. #12
    VBAX Regular
    Joined
    Jan 2009
    Posts
    93
    Location

    Smile

    Hi mdmackillop,

    Thank You for this tip according to
    my usage of select, which was not necessary.

    happy and sunny day to everybody, pavel

Posting Permissions

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