Extract Numbers from a String in Excel | Using Formula and VBA

Поделиться
HTML-код
  • Опубликовано: 5 сен 2024
  • Want to extract the numeric part or the text part from a string in Excel? In this video, I will show you how to extract numbers from a text string in Excel (and vice-versa, extract text from a string in Excel).
    The video covers the following topics:
    -- Extract Numbers/Text from String in Excel (using TEXTJOIN)
    -- Extract Numbers from String in Excel (using VBA)
    -- Extract Text from a String in Excel (using VBA)
    You can use any of the methods covered to separate text and numbers in Excel.
    If you're using Excel 2016, you can use the new TEXTJOIN formula which makes it a lot easier to extract numbers from a string. The below formula extracts the numbers from a string in a cell in Excel:
    =TEXTJOIN("",TRUE,IFERROR((MID(A2,ROW(INDIRECT("1:"&LEN(A2))),1)*1),""))
    But if you're not using Excel 2016 (and using prior versions such as Excel 2013/2010/2007/2003), you need to use a longer and more complicated formula (you can find that formula here: trumpexcel.com...
    And in case you are fine using VBA, you can easily create a custom User Defined Formula that takes the cell reference as the input and extracts the number part from a string. It's easy and neat with VBA.
    Personally, I prefer using the VBA method to separate Numbers and Text in Excel as it only requires the work once and can be used over and over again.
    Get numeric part in excel
    Free Excel Course - trumpexcel.com...
    Paid Online Training - trumpexcel.com...
    Best Excel Books: trumpexcel.com...
    ⚙️ Gear I Recommend:
    Camera - amzn.to/3bmHko7
    Screen Recorder - techsmith.z6rjha.net/26D9Q
    USB Mic - amzn.to/2uzhVHd
    Wireless Mic: amzn.to/3blQ8uk
    Lighting - amzn.to/2uxOxRv
    Subscribe to get awesome Excel Tips every week: www.youtube.co...
    Note: Some of these links here are affiliate links!
    #Excel #ExcelTips #ExcelTutorial

Комментарии • 72

  • @buak809
    @buak809 Год назад

    This is genius!

  • @Jim341046
    @Jim341046 5 лет назад +2

    Thank you - this is the ONLY formula that worked after hours of searching. Note to other users, CTRL-SHIFT-ENTER just adds =Arrayformula( to the formula which is ESSENTIAL for it to work. I was looking a set of prices big and small which are prefixed with odd symbols like ^~ instead of $,£ etc. Anyway it worked - phew. The old huge LEN formula worked on another set of data but not this one even though identical?! Happy to send you $5 if you get in touch.

    • @trumpexcel
      @trumpexcel  5 лет назад

      Glad you found the video useful James :)

  • @uncleyen
    @uncleyen 2 месяца назад

    dame, these formula just so smart and awesome. and super useful. you are rock Thanks so much

  • @FAVisionEnterprise
    @FAVisionEnterprise Год назад

    The video was very useful

  • @Stargeon
    @Stargeon 4 года назад

    I am trying to synthesize daily discharge data from a river for the last 10 years and the raw data cell values all have letters at the end,,,,, THIS SAVED ME. THANK YOU.

  • @joemomma7887
    @joemomma7887 3 года назад

    Thank you so much i keep watching your videos all the time.

  • @corduroy99
    @corduroy99 2 года назад

    Guy, you are a GENIUS! Thank you so much!

  • @Ashrafhaa1
    @Ashrafhaa1 3 года назад

    This Video is very helpful for both VBA and Even the Excel Functions as well, Thanks for the Creator

  • @jmathew6988
    @jmathew6988 3 года назад

    Hey Sumit. You're the best!

  • @TheVaibhav1982
    @TheVaibhav1982 2 года назад

    great trick special VBA part, thanks!!

  • @nadermounir8228
    @nadermounir8228 3 года назад

    Great tutorial especially the VBA one. Amazing 👏

  • @CarlosLopez-xi2rq
    @CarlosLopez-xi2rq 4 года назад

    Thanks so much Bro! I used your VBA code in access to extract numbers with dots, adapted it very sligtly and it works soooo perfectly! You're a crack!

  • @jaredfromtexas7484
    @jaredfromtexas7484 5 лет назад +21

    Good video. But this seems like a task for which Excel/Microsoft should create a specialized function. A user shouldn't have to create something so complex in order to achieve something fairly simple.

  • @sharifulhridoy
    @sharifulhridoy 5 лет назад

    you are Awesome and thanks for free teaching

  • @astuteleen3644
    @astuteleen3644 3 года назад

    Thank you so much! Helped a lot.

  • @rakhisaxena4352
    @rakhisaxena4352 5 лет назад +1

    Thanks a TON!! very simple and useful

  • @ibrahimnagi5936
    @ibrahimnagi5936 4 года назад +1

    thanks, wonderful VBA

  • @haninawaya9967
    @haninawaya9967 3 года назад

    Thank you Sumit, it helped me alot

  • @surajbhardwaj428
    @surajbhardwaj428 2 года назад

    Awesome bro... But to reach here need more practise for me...

  • @andrewwest5344
    @andrewwest5344 3 года назад

    Amazing, thanks for this, worked a treat

  • @anilkumar-pg2hi
    @anilkumar-pg2hi 3 года назад +1

    Hello Sir,
    Thank you very much,
    If cell has more then 25 character, which code need to use?

  • @andriikulishov3371
    @andriikulishov3371 3 года назад

    Thank you very much! Agree with Jared

  • @khalidstar2k
    @khalidstar2k 4 года назад

    Thanks !!! this video helped me a lot and saved my time

  • @LOVStudios
    @LOVStudios 4 года назад

    I'm subscribing off of this single experience! You are the shit. Let me see what else you have.

  • @Rkeev1
    @Rkeev1 3 года назад

    Great video I wish you would do one that sums all numbers in a cell even if the cell contains text values along with numbers. Another way is to use what you’ve shown is use one of your formulas then use substitute function in the next cell over and reference your cell with the formula and it would return the cell value not included in your formula result.

  • @mayirialcala6395
    @mayirialcala6395 3 года назад

    Thank you so much!!

  • @khanyisolesedi3651
    @khanyisolesedi3651 2 года назад

    This is great straight to the point, are you able do same thing on SQLite?

  • @GiteshBajaj
    @GiteshBajaj 4 года назад

    Oh my God...
    Beautiful

  • @Dev_Bartwal
    @Dev_Bartwal 7 лет назад +3

    Very osm Bansal sir
    Keep sharing yur Knowledge with us.
    Thanks a ton

  • @simbarashemashonganyika
    @simbarashemashonganyika 4 года назад

    brilliant i loved it

  • @meniporat3527
    @meniporat3527 3 года назад

    Now, with the new SEQUENCE function in Office 365, you can simplify the formula.
    Instead of:
    =TEXTJOIN("",TRUE,IFERROR(MID(A2,ROW(INDIRECT("1:"&LEN(A2))),1)*1,""))
    You can write:
    =TEXTJOIN("",TRUE,IFERROR(MID(A2,SEQUENCE(LEN(A2)),1)*1,""))
    SEQUENCE(LEN(A2)) Creates the same array as does: ROW(INDIRECT("1:"&LEN(A2)))

  • @adamtson
    @adamtson 4 года назад +1

    1:22 i think it is not for number of rows but for the number of characters in the cell.

  • @kameshsharma5164
    @kameshsharma5164 3 года назад

    Thanks sir, very helpful video. But I want to know whether we can extract more than one word. You have taught to extract one word from the middle of a line, in this video, but I want to get more than one word from a line.

  • @mariannataschinger1765
    @mariannataschinger1765 4 года назад +1

    What part of the formula should be edited in order to include a decimal point so that I can distinguish between something like 125 and 1.25?

  • @Louis-ws3tq
    @Louis-ws3tq 5 лет назад

    Hey Sumit, is there a way to start the Function without F( or Shift enter, because I want to aplly it to an entire column and not want to kick off every cell for itself? Thanks a bunch for your awesome video, so far you've been the onlz one to give me a solid solution!

  • @pedrocerdanovicente6281
    @pedrocerdanovicente6281 4 года назад +1

    Hello,
    How should I change the VBA Function in order to separate number with decimals. For example : 12.5ml - - - > 12.5
    Because with the given formula it is: 12.5ml - - >125

  • @meniporat3527
    @meniporat3527 3 года назад +1

    And one more comment, if I may:
    your solution does extract the digits from the text, but the result is left-aligned, which means that it isn’t a number.
    In order to convert the string into a “real” number, we can simply multiply the TEXTJOIN result by 1.
    Here is my version, a bit more legible and shorter….
    =TEXTJOIN(,1,IFERROR(MID(A2,SEQUENCE(LEN(A2)),1)*1," "))*1

  • @wayneedmondson1065
    @wayneedmondson1065 5 лет назад

    Hi Sumit.. awesome video and lesson. Love that TEXTJOIN solution to extract text or numbers from a string.. been trying to come up with that for years. I've looked at your UDF tutorial and so was familiar with the UDF solutions. Had to chuckle.. I also forgot to declare i and Result and got a variable not found error. Good learning on this one. Keep them coming. Thanks and Thumbs up!
    PS - For some reason, the download of the example file does not work.. when I click on it, I get a screen full of goofy characters and no download :(

  • @neraknerak1
    @neraknerak1 3 года назад

    I wish I could do on Mac. F9 to evaluate formula and shift return (Cmd+return on Mac) not working.I will try other way. But what if there is a decimal point, number not an integer?

  • @deepakmirchandani1348
    @deepakmirchandani1348 4 года назад

    great and very useful video sir.
    further if we have 3;55;78;22; .... type text in a single cell. then how to add these numbers and get the result in a cell. pl help. thanks

  • @sekhar6106
    @sekhar6106 3 года назад

    While using this formula mentioned in numeric part in "Office 365", it displaying the result even when I have not used the key CSE.
    I think, the CSE impact is not applicable in 365 version.

  • @hanudevelopingsystem7954
    @hanudevelopingsystem7954 3 года назад

    how to aumomate that in vba..?
    So without click and drag, just when run the macro, the result is auto fill in other column..
    Sorry maybe dumb question, but i really newbie in VBA
    #soryBadEnglish

  • @sumitboltahai
    @sumitboltahai 3 года назад

    You did not write end if how did your code work please explain

  • @leahgee2263
    @leahgee2263 4 года назад

    hello! how can i extract numbers with criteria through macro? for example, i need to extract 10 digit number that starts with 5609 or 5881 etc and the output will go to the rows / each 10 digit number on the same row but separate numbers? thank you so much!

  • @nithin.m2675
    @nithin.m2675 7 лет назад

    Hi sumit, Thanks for the video. But how can we tweak it around to get the set of numbers in the string. For example if the string is cost of 20 tickets is USD 100, how can we get the numeric out put as 20 100?

  • @rajeshakkineni5127
    @rajeshakkineni5127 3 года назад

    How you extract to see formula...

  • @entertainmenttrends1850
    @entertainmenttrends1850 2 года назад

    If it is a decimal number how we can extract

  • @madhubabu7570
    @madhubabu7570 7 лет назад

    Thanks for the video,I have a question can we get information from online website and paste in excel ??for example i need lowest price in particular product from Flipkart on daily basis and paste it on my excel sheet. Please suggest

  • @colinhuntley9729
    @colinhuntley9729 4 года назад

    hi summit, i also work with excel 2016, but a stand-alone version. This version does not include functions
    which the office365 version of excel 2016 offers! Is there a way to replace the textjoin function with something else?
    regards from berlin, germany
    colin

  • @sridharkrishnappanavanerth3388
    @sridharkrishnappanavanerth3388 4 года назад

    how call this function in all workbooks and worksheets new and old

  • @bryanyanez1680
    @bryanyanez1680 4 года назад

    My extract formula isn’t working. =RIGHT(A2,5) is there other settings I need to change? I keep getting error message

  • @TuanAnh-ey7dg
    @TuanAnh-ey7dg 7 лет назад

    Great thank you! But this formula need the textjoin function. Could you please advice for excel 2010 or 2013?

    • @TuanAnh-ey7dg
      @TuanAnh-ey7dg 7 лет назад

      It is very useful to me. Thank you very much!

    • @markthom6341
      @markthom6341 5 лет назад

      Try the following formula, I got it from another web site. =SUMPRODUCT(MID(0&A1,LARGE(INDEX(ISNUMBER(--MID(A1,ROW($1:$50),1))*
      ROW($1:$50),0),ROW($1:$25))+1,1)*10^ROW($1:$25)/10) and here is the web site link www.makeuseof.com/tag/extract-number-text-excel-function/

    • @Jim341046
      @Jim341046 5 лет назад

      @@markthom6341 I also tried this but it didn't work. Alternative is to use this textjoin function in 'google sheets' which has all the latest Excel 2016 formulas.

    • @azadariupdates
      @azadariupdates 4 года назад

      this is best ....thanks

  • @farhanmahmood9263
    @farhanmahmood9263 7 лет назад

    Awsome!!!

  • @naresh90sharma
    @naresh90sharma 7 лет назад

    hi sir thanks for send useful excel vedio. I have a one question. we have everyday received data from pivot table . I want to send mail to my boss in every evenings. data received from SQL by table form .

  • @shotasturua5041
    @shotasturua5041 4 года назад

    can i use numeric part for another formula
    ?

  • @theworldofparadise6529
    @theworldofparadise6529 5 лет назад

    Kindly copay and paste this formula for extract number in reply, bcz this is not working in my sheet

  • @memine226
    @memine226 7 лет назад

    thanks for the video. can you advise me why it only works for a short length of a string?
    for example, if the input is "the cost is USD 100", I get the correct answer "100".
    however, if the input is "ww24rg67sst65768rq245th", the answer is #VALUE!.
    thanks again.

  • @andreasvangeheinzl7474
    @andreasvangeheinzl7474 4 года назад +1

    I'm getting an error message: "Compile error: Expected: list seperator or )". I don't know what's wrong with my code, since it's written exactly like yours :/

  • @christopherwilson3085
    @christopherwilson3085 4 года назад +1

    I do not understand how someone would know this....

  • @kameshsharma5164
    @kameshsharma5164 3 года назад

    Sir, I request you to please make a formula in which I can extract two or three words from the middle of the line of a cell in Excel. I have made different formulas for both, but I am not able to form a formula by mixing them both. I am sharing both those formulas with you. You are requested to mix these two and make a formula so that I can extract two or three or four words from a line in a cell. Please Please
    (To extract one word from mid of line)
    =Trim(MID(SUBSTITUTE(B6," ",REPT(" ",LEN(B6))),(C6-1)*LEN(B6)+1,LEN(B6)))
    (To extract 2 or 3 word from the starting of the line)
    =TRIM(LEFT(B1,FIND("~",SUBSTITUTE(B1," ","~",A1)&"~")))

  • @dempseyroll96
    @dempseyroll96 4 года назад

    Teach me VBA in detail please

  • @shakilahammed9721
    @shakilahammed9721 5 лет назад +2

    how many of you are here after may june 2019 IT p4

  • @liridonbytyqi6735
    @liridonbytyqi6735 2 года назад

    hi can you please support me with a formula! i have a string "Toys 12: tre1 24 lvp" ( could you please support with a formula to get only numbers in separate cell each number (exaple in cell 1 to be number 12; in cell 2 to be number 1 and in cell 3 to be number 24

  • @mohanpal13555
    @mohanpal13555 5 лет назад

    Great please send me code visual code

  • @skippedtheusername
    @skippedtheusername 3 года назад

    Maybe this will help somebody:
    Example: extractstring(A2,11111)
    Function extractstring(myCell As Range, stringtype As String)
    Dim myString As String
    Dim myReplacementCharacter As String
    Dim myCharactersArray() As Variant
    Dim iCharacter As Variant
    Dim myString1 As String
    Dim myReplacementCharacter1 As String
    Dim myCharactersArray1() As Variant
    Dim length As Integer
    Dim startpoint As Integer
    Dim result As String
    Dim stringtype1 As String
    stringtype1 = "/" & stringtype & "/"
    length = Len(stringtype)
    myString = myCell.Value

    myCharactersArray = Array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", " ", ":", ",", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "-")
    myReplacementCharacter = "/"
    For Each iCharacter In myCharactersArray
    myString = Replace(Expression:=myString, Find:=iCharacter, Replace:=myReplacementCharacter)
    Next iCharacter
    myString1 = myString
    myCharactersArray1 = Array("0", "2", "3", "4", "5", "6", "7", "8", "9")
    myReplacementCharacter1 = "1"
    For Each iCharacter In myCharactersArray1
    myString1 = Replace(Expression:=myString1, Find:=iCharacter, Replace:=myReplacementCharacter1)
    Next iCharacter
    myString2 = "/" & myString1 & "/"
    startpoint = Application.WorksheetFunction.Find(stringtype1, myString2)
    result = Mid(myCell, startpoint, length)
    extractstring = result
    End Function

  • @davidnunez3318
    @davidnunez3318 4 года назад

    Extremely helpful. Thank you very much!