Splitting Specific length numbers from mixed data type with specific conditions, Formula; VBA CODE, Tried everything!!

menzenancy

New Member
Joined
Jul 27, 2022
Messages
3
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
0002786961 TRAK CDFA #: 0008787942 2722 2723 4536841 N/A 2786952 4345784 001018809~00077480

Above is an example of data line I need to split these into 3 types:
First column: starts with 2 and is of 4 digit (2722 2723 in above example) Second: starts with 2 and is of 7 digit(2786952 in above example); third: starts with 4 is of 7 digit (4345784 4536841 in above example).
I tried separating everything into different columns and then putting IF AND conditions that I mentioned above but the problem is not everything is getting separated and splitting everything is not efficient enough. I am not able to figure out a vba code for something that satisfies all the conditions and works too.
Can anyone help me out?

Code tried: IF(AND(LEFT(A4,1) = "2",LEN(A4) < 5), A4, "No") -This doesn't separate 4 digit numbers in between of text's or numbers.

Tried VBA CODE to extract numbers and text. But for numbers they were all extracted together without space so cant do anything with them.
Function GetNumber(CellRef As String)
Dim StringLength As Integer
StringLength = Len(CellRef)
For i = 1 To StringLength
If IsNumeric(Mid(CellRef, i, 1)) Then Result = Result & Mid(CellRef, i, 1)
Next i
GetNumber = Result
End Function


Function GetText(CellRef As String)
Dim StringLength As Integer
StringLength = Len(CellRef)
For i = 1 To StringLength
If Not (IsNumeric(Mid(CellRef, i, 1))) Then Result = Result & Mid(CellRef, i, 1)
Next i
GetText = Result
End Function

Would anyone be kind enough to help?
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Can you provide more samples of what the data looks like?
 
Upvote 0
4345784 001018809~00077480
2788 $0.00
2756/4357142 * NOT ISSUED*
2732/4358317 *NOT ISSUED*
0002782227 2707 & 2708
There is no set rule that the 4 digit number starting from2 is in the beginning or end. Same for all conditions, its gibbersih that needs to be sorted.
 
Upvote 0

Forum statistics

Threads
1,214,545
Messages
6,120,132
Members
448,947
Latest member
test111

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