Getting Acronyms with numbers to sort in number order

TCyber

New Member
Joined
Sep 12, 2023
Messages
10
Office Version
  1. 365
Platform
  1. Windows
  2. Web
Hello, I am trying to make a pivot table with a large amount of different acronyms/number combinations. The problem is I have numbers like TB-1, TB-11, TB-2(3), DW-5(7), DW-6. I really need them to sort in the number after the dash. So it would look in a column in the order like this TB-1 | TB-1(1) | TB-2..............TB-10 | TB-11 and so on. right now it puts 11 before 2, there are 100's of these I need to verify and this would make it so much easier.

Office 365
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Book1
AB
1inputoutpout
2AX-8AX-8
3AX-10AX-10
4BF-1BF-1
5BF-2BF-2
6BF-2(3)BF-2(3)
7BF-20(1)BF-20(1)
Sheet2
Cell Formulas
RangeFormula
B2:B7B2=SORTBY(A2:A7,IF(LEN(SUBSTITUTE(MID(A2:A7,4,2),"(",""))=1,REPLACE(A2:A7,4,0,0),A2:A7))
Dynamic array formulas.
 
Upvote 1
And for the VBA, change the regex to

VBA Code:
.Pattern = "(.*-)(\d(?=\(|$))(.*)"
 
Upvote 1
It worked thank you!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
Upvote 0
Last question, is there any specific process I need to do to make sure that the data sorted reflects when I put it into a pivot table?
 
Upvote 0
If you want to make sure that everything is sorted properly in the pivot table, you could use this formula where you leave the "0"
Are you using the VBA or the formula?

Book1
AB
1inputoutput
2BF-20(1)AX-08
3BF-2AX-10
4BF-1BF-01
5AX-10BF-02
6BF-2(3)BF-02(3)
7AX-8BF-20(1)
Sheet2
Cell Formulas
RangeFormula
B2:B7B2=SORT(IF(LEN(SUBSTITUTE(MID(A2:A7,4,2),"(",""))=1,REPLACE(A2:A7,4,0,0),A2:A7))
Dynamic array formulas.
 
Upvote 0
If you want to make sure that everything is sorted properly in the pivot table, you could use this formula where you leave the "0"
Are you using the VBA or the formula?

Book1
AB
1inputoutput
2BF-20(1)AX-08
3BF-2AX-10
4BF-1BF-01
5AX-10BF-02
6BF-2(3)BF-02(3)
7AX-8BF-20(1)
Sheet2
Cell Formulas
RangeFormula
B2:B7B2=SORT(IF(LEN(SUBSTITUTE(MID(A2:A7,4,2),"(",""))=1,REPLACE(A2:A7,4,0,0),A2:A7))
Dynamic array formulas.
Just the formula, never heard of VPA before getting here this morning. New job requires some deep dive knowledge of Excel. No offense but I have avoided office products for years. I was always behind the scenes as a cyber/developer so I have some understanding of code. Any links or info you could provide would be much appreciated. I know you do not want to answer the 50,000 questions I have in excel.
 
Upvote 0
Just the formula, never heard of VPA before getting here this morning. New job requires some deep dive knowledge of Excel. No offense but I have avoided office products for years. I was always behind the scenes as a cyber/developer so I have some understanding of code. Any links or info you could provide would be much appreciated. I know you do not want to answer the 50,000 questions I have in excel.
I was a past sys admin and clicking until you get the outcome you want does not work that great in Excel.
 
Upvote 0

Forum statistics

Threads
1,215,077
Messages
6,122,995
Members
449,094
Latest member
masterms

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