Excel extract specific number from cell










2















i have excel cell inputs like this:



Line 644: 6


or



Line 1004:


the only thing i need is the number next to the ":" so in the above cases i need



644 and 1004. all cells are formatted as "general" is there a quick way to remove the other not needed characters and only extract the needed numbers ?



i tried with =LEFT(Q2,4) for the first example above, but this gives me an error "The formula you typed contains an error"










share|improve this question






















  • Do all cells start with "Line "?

    – cybernetic.nomad
    Nov 14 '18 at 16:22











  • Try =TRIM(MID(Q2,FIND(" ",Q2),FIND(":",Q2)-FIND(" ",Q2)))

    – dwirony
    Nov 14 '18 at 16:28











  • @cybernetic yes all cells start with "Line"

    – friggler
    Nov 15 '18 at 8:26















2















i have excel cell inputs like this:



Line 644: 6


or



Line 1004:


the only thing i need is the number next to the ":" so in the above cases i need



644 and 1004. all cells are formatted as "general" is there a quick way to remove the other not needed characters and only extract the needed numbers ?



i tried with =LEFT(Q2,4) for the first example above, but this gives me an error "The formula you typed contains an error"










share|improve this question






















  • Do all cells start with "Line "?

    – cybernetic.nomad
    Nov 14 '18 at 16:22











  • Try =TRIM(MID(Q2,FIND(" ",Q2),FIND(":",Q2)-FIND(" ",Q2)))

    – dwirony
    Nov 14 '18 at 16:28











  • @cybernetic yes all cells start with "Line"

    – friggler
    Nov 15 '18 at 8:26













2












2








2








i have excel cell inputs like this:



Line 644: 6


or



Line 1004:


the only thing i need is the number next to the ":" so in the above cases i need



644 and 1004. all cells are formatted as "general" is there a quick way to remove the other not needed characters and only extract the needed numbers ?



i tried with =LEFT(Q2,4) for the first example above, but this gives me an error "The formula you typed contains an error"










share|improve this question














i have excel cell inputs like this:



Line 644: 6


or



Line 1004:


the only thing i need is the number next to the ":" so in the above cases i need



644 and 1004. all cells are formatted as "general" is there a quick way to remove the other not needed characters and only extract the needed numbers ?



i tried with =LEFT(Q2,4) for the first example above, but this gives me an error "The formula you typed contains an error"







excel format cell






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 14 '18 at 16:19









frigglerfriggler

629




629












  • Do all cells start with "Line "?

    – cybernetic.nomad
    Nov 14 '18 at 16:22











  • Try =TRIM(MID(Q2,FIND(" ",Q2),FIND(":",Q2)-FIND(" ",Q2)))

    – dwirony
    Nov 14 '18 at 16:28











  • @cybernetic yes all cells start with "Line"

    – friggler
    Nov 15 '18 at 8:26

















  • Do all cells start with "Line "?

    – cybernetic.nomad
    Nov 14 '18 at 16:22











  • Try =TRIM(MID(Q2,FIND(" ",Q2),FIND(":",Q2)-FIND(" ",Q2)))

    – dwirony
    Nov 14 '18 at 16:28











  • @cybernetic yes all cells start with "Line"

    – friggler
    Nov 15 '18 at 8:26
















Do all cells start with "Line "?

– cybernetic.nomad
Nov 14 '18 at 16:22





Do all cells start with "Line "?

– cybernetic.nomad
Nov 14 '18 at 16:22













Try =TRIM(MID(Q2,FIND(" ",Q2),FIND(":",Q2)-FIND(" ",Q2)))

– dwirony
Nov 14 '18 at 16:28





Try =TRIM(MID(Q2,FIND(" ",Q2),FIND(":",Q2)-FIND(" ",Q2)))

– dwirony
Nov 14 '18 at 16:28













@cybernetic yes all cells start with "Line"

– friggler
Nov 15 '18 at 8:26





@cybernetic yes all cells start with "Line"

– friggler
Nov 15 '18 at 8:26












2 Answers
2






active

oldest

votes


















0














How about:



=MID(MID(A1,1,FIND(":",A1)-1),FIND(" ",MID(A1,1,FIND(":",A1)-1))+1,9999)


enter image description here



MUCH more reliable would be:



Public Function GetNumber(r As Range) As Variant
Dim arr, L As Long, i As Long, CH As String, temp As String

GetNumber = ""
arr = Split(r.Value, ":")
L = Len(arr(0))
CH = ""
temp = ""

For i = L To 1 Step -1
CH = Mid(arr(0), i, 1)
If CH Like "[0-9]" Then
temp = CH & temp
Else
GetNumber = temp
Exit Function
End If
Next i

GetNumber = temp
End Function


Because this UDF() does not rely on a single space before the number.



BY THE WAY:



if a formula like:



 =LEFT(Q2,4)


does not work, next try:



 =LEFT(Q2;4)


instead.






share|improve this answer

























  • i will try it with your function because with these formulas i keep getting "The formula you typed contains an error"

    – friggler
    Nov 15 '18 at 8:25











  • @friggler see my By the way

    – Gary's Student
    Nov 15 '18 at 11:50











  • thank you so much that ";" did the trick :-) now the formulas work. god i hate excel

    – friggler
    Nov 15 '18 at 12:51


















0














Slightly shorter than other formula offers (so far) while also converting result to Numeric format:



=1*MID(LEFT(A1,FIND(":",A1)-1),6,LEN(A1))





share|improve this answer

























  • i keep getting this "The formula you typed contains an error". i tried all suggested formulas. i also tried selecting the entire column and changing the format to "text" or "number" but then nothing happens the formula e.g. "=TRIM(...)" is just inserted as text

    – friggler
    Nov 15 '18 at 8:24










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53304598%2fexcel-extract-specific-number-from-cell%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














How about:



=MID(MID(A1,1,FIND(":",A1)-1),FIND(" ",MID(A1,1,FIND(":",A1)-1))+1,9999)


enter image description here



MUCH more reliable would be:



Public Function GetNumber(r As Range) As Variant
Dim arr, L As Long, i As Long, CH As String, temp As String

GetNumber = ""
arr = Split(r.Value, ":")
L = Len(arr(0))
CH = ""
temp = ""

For i = L To 1 Step -1
CH = Mid(arr(0), i, 1)
If CH Like "[0-9]" Then
temp = CH & temp
Else
GetNumber = temp
Exit Function
End If
Next i

GetNumber = temp
End Function


Because this UDF() does not rely on a single space before the number.



BY THE WAY:



if a formula like:



 =LEFT(Q2,4)


does not work, next try:



 =LEFT(Q2;4)


instead.






share|improve this answer

























  • i will try it with your function because with these formulas i keep getting "The formula you typed contains an error"

    – friggler
    Nov 15 '18 at 8:25











  • @friggler see my By the way

    – Gary's Student
    Nov 15 '18 at 11:50











  • thank you so much that ";" did the trick :-) now the formulas work. god i hate excel

    – friggler
    Nov 15 '18 at 12:51















0














How about:



=MID(MID(A1,1,FIND(":",A1)-1),FIND(" ",MID(A1,1,FIND(":",A1)-1))+1,9999)


enter image description here



MUCH more reliable would be:



Public Function GetNumber(r As Range) As Variant
Dim arr, L As Long, i As Long, CH As String, temp As String

GetNumber = ""
arr = Split(r.Value, ":")
L = Len(arr(0))
CH = ""
temp = ""

For i = L To 1 Step -1
CH = Mid(arr(0), i, 1)
If CH Like "[0-9]" Then
temp = CH & temp
Else
GetNumber = temp
Exit Function
End If
Next i

GetNumber = temp
End Function


Because this UDF() does not rely on a single space before the number.



BY THE WAY:



if a formula like:



 =LEFT(Q2,4)


does not work, next try:



 =LEFT(Q2;4)


instead.






share|improve this answer

























  • i will try it with your function because with these formulas i keep getting "The formula you typed contains an error"

    – friggler
    Nov 15 '18 at 8:25











  • @friggler see my By the way

    – Gary's Student
    Nov 15 '18 at 11:50











  • thank you so much that ";" did the trick :-) now the formulas work. god i hate excel

    – friggler
    Nov 15 '18 at 12:51













0












0








0







How about:



=MID(MID(A1,1,FIND(":",A1)-1),FIND(" ",MID(A1,1,FIND(":",A1)-1))+1,9999)


enter image description here



MUCH more reliable would be:



Public Function GetNumber(r As Range) As Variant
Dim arr, L As Long, i As Long, CH As String, temp As String

GetNumber = ""
arr = Split(r.Value, ":")
L = Len(arr(0))
CH = ""
temp = ""

For i = L To 1 Step -1
CH = Mid(arr(0), i, 1)
If CH Like "[0-9]" Then
temp = CH & temp
Else
GetNumber = temp
Exit Function
End If
Next i

GetNumber = temp
End Function


Because this UDF() does not rely on a single space before the number.



BY THE WAY:



if a formula like:



 =LEFT(Q2,4)


does not work, next try:



 =LEFT(Q2;4)


instead.






share|improve this answer















How about:



=MID(MID(A1,1,FIND(":",A1)-1),FIND(" ",MID(A1,1,FIND(":",A1)-1))+1,9999)


enter image description here



MUCH more reliable would be:



Public Function GetNumber(r As Range) As Variant
Dim arr, L As Long, i As Long, CH As String, temp As String

GetNumber = ""
arr = Split(r.Value, ":")
L = Len(arr(0))
CH = ""
temp = ""

For i = L To 1 Step -1
CH = Mid(arr(0), i, 1)
If CH Like "[0-9]" Then
temp = CH & temp
Else
GetNumber = temp
Exit Function
End If
Next i

GetNumber = temp
End Function


Because this UDF() does not rely on a single space before the number.



BY THE WAY:



if a formula like:



 =LEFT(Q2,4)


does not work, next try:



 =LEFT(Q2;4)


instead.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 15 '18 at 11:49

























answered Nov 14 '18 at 16:49









Gary's StudentGary's Student

73.4k94063




73.4k94063












  • i will try it with your function because with these formulas i keep getting "The formula you typed contains an error"

    – friggler
    Nov 15 '18 at 8:25











  • @friggler see my By the way

    – Gary's Student
    Nov 15 '18 at 11:50











  • thank you so much that ";" did the trick :-) now the formulas work. god i hate excel

    – friggler
    Nov 15 '18 at 12:51

















  • i will try it with your function because with these formulas i keep getting "The formula you typed contains an error"

    – friggler
    Nov 15 '18 at 8:25











  • @friggler see my By the way

    – Gary's Student
    Nov 15 '18 at 11:50











  • thank you so much that ";" did the trick :-) now the formulas work. god i hate excel

    – friggler
    Nov 15 '18 at 12:51
















i will try it with your function because with these formulas i keep getting "The formula you typed contains an error"

– friggler
Nov 15 '18 at 8:25





i will try it with your function because with these formulas i keep getting "The formula you typed contains an error"

– friggler
Nov 15 '18 at 8:25













@friggler see my By the way

– Gary's Student
Nov 15 '18 at 11:50





@friggler see my By the way

– Gary's Student
Nov 15 '18 at 11:50













thank you so much that ";" did the trick :-) now the formulas work. god i hate excel

– friggler
Nov 15 '18 at 12:51





thank you so much that ";" did the trick :-) now the formulas work. god i hate excel

– friggler
Nov 15 '18 at 12:51













0














Slightly shorter than other formula offers (so far) while also converting result to Numeric format:



=1*MID(LEFT(A1,FIND(":",A1)-1),6,LEN(A1))





share|improve this answer

























  • i keep getting this "The formula you typed contains an error". i tried all suggested formulas. i also tried selecting the entire column and changing the format to "text" or "number" but then nothing happens the formula e.g. "=TRIM(...)" is just inserted as text

    – friggler
    Nov 15 '18 at 8:24















0














Slightly shorter than other formula offers (so far) while also converting result to Numeric format:



=1*MID(LEFT(A1,FIND(":",A1)-1),6,LEN(A1))





share|improve this answer

























  • i keep getting this "The formula you typed contains an error". i tried all suggested formulas. i also tried selecting the entire column and changing the format to "text" or "number" but then nothing happens the formula e.g. "=TRIM(...)" is just inserted as text

    – friggler
    Nov 15 '18 at 8:24













0












0








0







Slightly shorter than other formula offers (so far) while also converting result to Numeric format:



=1*MID(LEFT(A1,FIND(":",A1)-1),6,LEN(A1))





share|improve this answer















Slightly shorter than other formula offers (so far) while also converting result to Numeric format:



=1*MID(LEFT(A1,FIND(":",A1)-1),6,LEN(A1))






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 14 '18 at 21:05

























answered Nov 14 '18 at 20:42









pnutspnuts

48.5k76299




48.5k76299












  • i keep getting this "The formula you typed contains an error". i tried all suggested formulas. i also tried selecting the entire column and changing the format to "text" or "number" but then nothing happens the formula e.g. "=TRIM(...)" is just inserted as text

    – friggler
    Nov 15 '18 at 8:24

















  • i keep getting this "The formula you typed contains an error". i tried all suggested formulas. i also tried selecting the entire column and changing the format to "text" or "number" but then nothing happens the formula e.g. "=TRIM(...)" is just inserted as text

    – friggler
    Nov 15 '18 at 8:24
















i keep getting this "The formula you typed contains an error". i tried all suggested formulas. i also tried selecting the entire column and changing the format to "text" or "number" but then nothing happens the formula e.g. "=TRIM(...)" is just inserted as text

– friggler
Nov 15 '18 at 8:24





i keep getting this "The formula you typed contains an error". i tried all suggested formulas. i also tried selecting the entire column and changing the format to "text" or "number" but then nothing happens the formula e.g. "=TRIM(...)" is just inserted as text

– friggler
Nov 15 '18 at 8:24

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53304598%2fexcel-extract-specific-number-from-cell%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3

Museum of Modern and Contemporary Art of Trento and Rovereto