VBA BubbleSort Worksheet Alphanumerically

decadence

Well-known Member
Joined
Oct 9, 2015
Messages
525
Office Version
  1. 365
  2. 2016
  3. 2013
  4. 2010
  5. 2007
Platform
  1. Windows
Hi, Is it possible to sort a worksheet Alphanumerically by the cell values in a column without a helper column? I would Like to put a column of alphanumeric data into a List then Alphanumeric sort that List Alphanumerically, Then use that sorted List to sort the worksheet of data if that makes sense, Can anyone help with this please

Key factors:
The alphanumeric data may contain dashes and/or underscores i.e. C1_1-1, C215-2_1, DTR3-3, DTR43_21, J5_J1-1, QR10_Q1_3
The range of alphanumeric data is varied rows and up to 10 columns of data
There will always be a header to reference from which also may have a varied name
Needs to be sorted by letter first then by number

Example
From this
C1SomethingSomethingSomethingSomething
C10Something ElseSomething ElseSomething ElseSomething Else
C3InfoInfoInfoInfo
B2OtherOtherOtherOther

To this
B2OtherOtherOtherOther
C1SomethingSomethingSomethingSomething
C3InfoInfoInfoInfo
C10Something ElseSomething ElseSomething ElseSomething Else
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
I suggest that you update your Account details (click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)


The alphanumeric data may contain dashes and/or underscores i.e. C1_1-1, C215-2_1, DTR3-3, DTR43_21, J5_J1-1, QR10_Q1_3
.. but none of your sample data is like this so it is unclear just how you would want the sorting of such data to work.
 
Upvote 0
I am currently using 2007/2010 but will shortly be going to 2013/2016

The comma delimited example was meant to represent examples of the data I may get, not as a comma delimited string.

The issue I face is that my data can vary and the normal sort does not sort Alphanumerically without using helper columns which I am trying to avoid.

To clarify.... my data would look something like this below

QR10_Q1_3SomethingSomethingSomethingSomething
C10Something ElseSomething ElseSomething ElseSomething Else
DTR3-3InfoInfoInfoInfo
C215-2_1OtherOtherOtherOther

After Sorting

C10Something ElseSomething ElseSomething ElseSomething Else
C215-2_1OtherOtherOtherOther
DTR3-3InfoInfoInfoInfo
QR10_Q1_3SomethingSomethingSomethingSomething
 
Upvote 0
The comma delimited example was meant to represent examples of the data I may get, not as a comma delimited string.
Yes, I understood that. :)
The issue was that your original examples did not include any values with hyphens or underscores.

Your latest examples do, but still shed no light on what the rules for sorting actually are. For example, what order should these values come in and why?
Can you put into words what the sorting rules are?

decadence 2020-06-17 1.xlsm
A
1C215-2_1
2C215_2-1
3C2152_1
4C215_D
5C2-15_C
6C2-15_X
Sheet2
 
Upvote 0
So currently I have a helper column that helps sort by split out cell values to sort all the rows by the helper columns like below, the only rule is to sort by the hyphen first then by Underscore if the cell contains both

Sort 1stSort 2ndSort 3rdSort 4thSort 5thSort 6thSort 7th
QR10_Q1_3

Essentially I don't want to use the helper column and contain this sort method into a bubble sort, so ideally get the range of cells, put them into an array, split the array then sort the split array and implement that sorted array to sort the rows
 
Upvote 0

Forum statistics

Threads
1,215,046
Messages
6,122,849
Members
449,096
Latest member
Erald

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top