Need a user defined function/macro to separate data in a cell

bobby_smith

Board Regular
Joined
Apr 16, 2014
Messages
90
I would like some assistance creating two separate “user defined functions” whereby when I select the data, it separates the data to either number or text.
I’ve included the format that the data will normally be in.
Also please note that i'm requesting a function and not a macro so that for example I can type in cell
B2: =function1(A2) and get the results that are shown in cell B2

Excel 2010
ABC
1Original DataFunction 1Function 2
2TD 5678 TEXT TEXT5678TEXT TEXT
3TI 76 TEXT TEXT TEXT TEXT76TEXT TEXT TEXT TEXT
4NT 254 TEXT TEXT TEXT254TEXT TEXT TEXT

<tbody>
</tbody>
Sheet3
It will always be two letters,followed by numbers that can range from 1 digit to four digits, and then text that can be any length.
I currently use the text features such as LEFT(), MID(), RIGHT(), but my results are inconsistent because both the numbers and text may vary in length.
I’ve also tried the “Text to Column” feature, however the result is inconsistent because the text at the end varies in length. For example, if I have 200 lines of items of different length, the text to column feature would sometimes put data in adjacent cells overwriting information already in those cells
What I need the function to do is, upon selecting the data
1) Only the numbers remain
2) Only the text after the numbers remain.
Hence Why I would prefer two separate macros.

I would really appreciate your help with this.
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
These formulae should do what you want...
A​
B​
C​
2​
Original DataFunction 1Function 2
3​
TD 5678 TEXT TEXT5678TEXT TEXT
4​
TI 76 TEXT TEXT TEXT TEXT76TEXT TEXT TEXT TEXT
5​
NT 254 TEXT TEXT TEXT254TEXT TEXT TEXT
B3=LEFT(MID(A3,FIND(" ",A3,1)+1,99),FIND(" ",MID(A3,FIND(" ",A3,1)+1,99),1)-1)
C3=MID(A3,FIND(B3,A3,1)+LEN(B3)+1,99)
both copied down

You could add =if(A3="","", at the start, if needed
 
Upvote 0
Thank you FDibbins for replying to my post. The formula works as required perfectly.
IF possible, can you write it as VBA user defined function.
I've attempted converting it to a function, but I've not been able to code the section that contains the Find function.
From what I'm reading the find function in vba has a different syntax to the excel find, and I'm not getting it to work.

Any help would be much appreciated even if its only the find function.
 
Upvote 0
Solution:
For anyone with the same problem, I was able to get my desired solution from hicker95:http://www.mrexcel.com/forum/excel-...fined-function-separate-data.html#post4121267

Function ExtractNumber(NbrText As Range) As Long
' hiker95, 04/05/2015, ME846714
' If A2 contains "TD 5678 TEXT TEXT" without the " characters
' In B2 enter "=ExtractNumber(A2)" without the " characters
' B2 will display: 5678
Dim t As String, s, i As Long
s = Split([NbrText].Value, " ")
For i = LBound(s) To UBound(s)
If IsNumeric(s(i)) Then
ExtractNumber = s(i)
Exit For
End If
Next i
End Function


Function ExtractText(NbrText As Range) As String
' hiker95, 04/05/2015, ME846714
' If A2 contains "TD 5678 TEXT TEXT" without the " characters
' In C2 enter "=ExtractText(A2)" without the " characters
' C2 will display: TEXT TEXT
Dim t As String, s, i As Long
s = Split([NbrText].Value, " ")
For i = LBound(s) + 2 To UBound(s)
t = t & s(i) & " "
Next i
If Right(t, 1) = " " Then
t = Left(t, Len(t) - 1)
End If
ExtractText = t
End Function
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,424
Members
448,961
Latest member
nzskater

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