Consulting

Results 1 to 5 of 5

Thread: VBA Code: ascending order of the columns

  1. #1

    VBA Code: ascending order of the columns

    Hi,
    I have a spreadsheet which is having Column A to B. I want to sort the column A as alphabetical order (So cells which are having same values should come together), so all columns should adjust with that accordingly.

    can we able to achieve this scenario in VBA code? If yes, please provide me the sample code.


    Sample data for the scenario is as below:

    Column A Column B
    KALA $58
    KAZO $123.7
    KA55 $23.5
    CBHY $14.0
    AMJ0 $99
    CBHY $73.0
    AMJ0 $34
    KAZO $13.0
    KA55 $28.5
    CT00 $12
    KALA $76
    KL76 $34

    Regards,
    Sri

  2. #2
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    Record a macro:

    Press Record Macro
    Select columns A and B (and all others that you want to be moved with the sort)
    Sort on column A
    Press Stop Recording.

  3. #3
    .
    Last edited by murthysri272; 02-23-2016 at 01:39 PM.

  4. #4
    Okay Mike,
    I got it.
    Thanks for your suggestion.

    After sort My data (INPUT) is as below, is there anyway I can get my result (OUTPUT) using VBA Macros? If it is feasible please help me with sample code.

    Input:

    Column A Column B

    AMJ0 $34
    AMJ0 $99

    CBHY $14.0
    CBHY $73.0

    CT00 $12

    KALA $58
    KALA $76

    KAZO $123.7
    KAZO $13.0

    KA55 $28.5
    KA55 $23.5

    KL76 $34

    Output:

    AMJ0 $133

    CBHY $87.0

    CT00 $12

    KALA $134

    KAZO $136.7

    KA55 $52.0

    KL76 $34


    Regards,
    Sri

  5. #5
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    The formula =SUMIF(A:A, "AMJ0", B:B) will give you the sum for AMJ0

    You can use AdvancedFilter to generate a list of unique names and then put a formula in the next column.

    OHHH... by the way. Everyone should know that there is a cross post at
    http://www.ozgrid.com/forum/showthread.php?t=198782

Posting Permissions

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