+ Reply to Thread
Results 1 to 9 of 9

VBA Code for Sorting Values inside Cell for two columns

  1. #1
    Forum Contributor
    Join Date
    11-24-2019
    Location
    India
    MS-Off Ver
    Ms. Office 2016
    Posts
    169

    Exclamation VBA Code for Sorting Values inside Cell for two columns

    Hello,

    I need to sort values given in attachment sample sheet. Values will be in G and H columns. For sample purpose only two Sr No are taken but in actual number of data may extend upto 50 Sr No.. Also code should not affect values in other cells. Also please explain where ranges can be changed if i change position of the values in example.


    Thank you.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,945

    Re: VBA Code for Sorting Values inside Cell for two columns

    You need to show not only what you have, but what you want based on the examples that you show.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Forum Contributor
    Join Date
    11-24-2019
    Location
    India
    MS-Off Ver
    Ms. Office 2016
    Posts
    169

    Re: VBA Code for Sorting Values inside Cell for two columns

    Hello,
    Thanks for reply,
    I have attached two files. one is showing data before execution of code. Data in that file is in original nature.

    But when code executes it will sort values in that cell only in ascending order. It will not create new sheet or new file, instead of that it will sort data in the same cell of that file.

    In second attached file result after code execution is shown.

  4. #4
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,945

    Re: VBA Code for Sorting Values inside Cell for two columns

    Select the cells that you want to have sorted, then run this code.

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    11-24-2019
    Location
    India
    MS-Off Ver
    Ms. Office 2016
    Posts
    169

    Re: VBA Code for Sorting Values inside Cell for two columns

    Truly very thankful to you. Its working smoothly. Thanks a lot.

  6. #6
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,230

    Re: VBA Code for Sorting Values inside Cell for two columns

    I know this is solved...But I notice that above code sorts
    10.10.100.110.12.150.2.20.200.225.4.4.5.5.52.6.8.8
    Should it not be...As per your result file attached...
    2.4.4.5.5.6.8.8.10.10.12.20.52.100.110.150.200.225

    Just for future reference...Another Option...

    If it should be as per first result in red then with below code...remove
    Please Login or Register  to view this content.
    If it should be as second result, then leave below code as is...

    Please Login or Register  to view this content.
    to edit Bernie code for 2nd sort...
    Please Login or Register  to view this content.
    Last edited by sintek; 03-19-2022 at 03:10 AM.
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  7. #7
    Forum Contributor
    Join Date
    11-24-2019
    Location
    India
    MS-Off Ver
    Ms. Office 2016
    Posts
    169

    Re: VBA Code for Sorting Values inside Cell for two columns

    Grateful to you. Thanks for your keen observation which got skipped in hurry. Code is working fine. Thanks again. Adding reputation

  8. #8
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,230

    Re: VBA Code for Sorting Values inside Cell for two columns

    ..........................
    Thanks.png

  9. #9
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,945

    Re: VBA Code for Sorting Values inside Cell for two columns

    It's odd - my code worked perfectly on the example workbook, so I'm not sure why it gave you the results it did.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 1
    Last Post: 08-18-2020, 01:59 AM
  2. conditional formatting on one cell inside a table that works with sorting-filtering
    By netanel99 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 10-09-2018, 11:55 PM
  3. Sorting a comma list inside a single cell
    By hintysen in forum Excel General
    Replies: 2
    Last Post: 06-15-2018, 10:29 AM
  4. sorting two columns and write the sorted values on two columns in a different sheet
    By virsojour in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-22-2010, 04:38 AM
  5. Sorting Columns using Code
    By boylejob in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-29-2008, 06:17 PM
  6. Sorting Numbers Inside a Cell
    By totallysoccer in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-14-2008, 10:52 AM
  7. IF Then inside a cell, also; VBA Code IF Thens.
    By gjon in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 04-08-2005, 04:35 AM

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