+ Reply to Thread
Results 1 to 10 of 10

Macro to delete all characters after the second number 1 in specific cell

  1. #1
    Forum Contributor
    Join Date
    07-28-2012
    Location
    madrid
    MS-Off Ver
    Excel 2010 at work excel 2016
    Posts
    1,102

    Macro to delete all characters after the second number 1 in specific cell

    Hi. I extract data from a internal application into excel. In one of the cell it give me all the possibilities from the application.
    I have found out of what data and rule i need to keep the right result in the cell.
    I need to delete all characters before the second number 1 in the cell.
    I have tried but so far no success. I need a macro because this is a part of other macros to put the data in order,

    Example. 1-91456211-1212 have to be 1-9
    10-49145245 to be 10-49
    100-249145875 can be more numbers. have to be 100-249
    and also text. Unknown/ answer1 in this case it have to be unknown/answers. only in this case when this text are its before the first number one

    Please have a look
    Thanks in advance

    Abjac

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Macro to delete all characters after the second number 1 in specific cell

    Try
    Please Login or Register  to view this content.

  3. #3
    Forum Expert
    Join Date
    03-23-2004
    Location
    London, England
    MS-Off Ver
    Excel 2019
    Posts
    7,076

    Re: Macro to delete all characters after the second number 1 in specific cell

    UDF solution, amend as required

    Please Login or Register  to view this content.
    Regards
    Special-K

    Ensure you describe your problem clearly, I have little time available to solve these problems and do not appreciate numerous changes to them.

  4. #4
    Forum Contributor
    Join Date
    07-28-2012
    Location
    madrid
    MS-Off Ver
    Excel 2010 at work excel 2016
    Posts
    1,102

    Re: Macro to delete all characters after the second number 1 in specific cell

    Hi Jindon and also special-k. Jindon i tried your code on this string . Its in special cell not a range cell B18
    this was the string.
    10-491-910-4950-99100-249250-499500+Unknown/No answer1-910-4950-99100-249250-499500+Unknown/No answer
    it left only answer back but the answer should be 10-49
    I change your code to
    Please Login or Register  to view this content.
    Special - K maybe its my missing knowledge but how do i use this public function
    Abjac

  5. #5
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Macro to delete all characters after the second number 1 in specific cell

    Test this simple UDF - it works for the numbers
    (workbook containing UDF is attached to this post)
    Please Login or Register  to view this content.
    ExtractString.jpg


    and also text. Unknown/ answer1 in this case it have to be unknown/answers.
    only in this case when this text are its before the first number one

    Please give some examples of what we are dealing with
    Attached Files Attached Files
    Last edited by kev_; 03-07-2018 at 09:07 AM.
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Macro to delete all characters after the second number 1 in specific cell

    OOps, should be

    Please Login or Register  to view this content.

  7. #7
    Forum Expert
    Join Date
    03-23-2004
    Location
    London, England
    MS-Off Ver
    Excel 2019
    Posts
    7,076

    Re: Macro to delete all characters after the second number 1 in specific cell

    Quote Originally Posted by abjac View Post
    Hi Jindon and also special-k. Jindon i tried your code on this string . Its in special cell not a range cell B18
    this was the string.
    10-491-910-4950-99100-249250-499500+Unknown/No answer1-910-4950-99100-249250-499500+Unknown/No answer
    it left only answer back but the answer should be 10-49
    I change your code to
    Please Login or Register  to view this content.
    Special - K maybe its my missing knowledge but how do i use this public function
    Abjac
    Alt-F11 to VBA Editor
    Rigfht Click Modules
    Select Insert ==> Module
    Paste code in editor on the right

  8. #8
    Forum Contributor
    Join Date
    07-28-2012
    Location
    madrid
    MS-Off Ver
    Excel 2010 at work excel 2016
    Posts
    1,102

    Re: Macro to delete all characters after the second number 1 in specific cell

    This is some real strings and it only have to be in one cell B18

    10-491-910-4950-99100-249250-499500+Unknown/No answer1-910-4950-99100-249250-499500+Unknown/No answer result have to be 10-49
    1-910-4950-99100-249250-499500+Unknown/No answer1-910-4950-99100-249250-499500+Unknown/No answer result have to be 1-9
    This is the number rule
    then one example with the text here only before the first number 1.
    Unknown/No answer14950-99100-249250-499500+Unknown/No answer1-910-4950-99100-2 result have to be Unknown/No answer
    This is the number rule

    But the strings can be various,

    macro will be the best for me.
    sincerely Abjac

  9. #9
    Forum Contributor
    Join Date
    07-28-2012
    Location
    madrid
    MS-Off Ver
    Excel 2010 at work excel 2016
    Posts
    1,102

    Re: Macro to delete all characters after the second number 1 in specific cell

    Hi Jindon.
    Tried your last code it works like a charm . Thanks alot just great
    sincerely
    Abjac

  10. #10
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Macro to delete all characters after the second number 1 in specific cell

    You are welcome and thanks for the rep.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] A macro for removing characters after a specific number of character
    By ugalskov in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-19-2016, 10:19 AM
  2. [SOLVED] If cell contains 3 or more specific characters then delete row
    By RichTea88 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-18-2014, 08:12 AM
  3. Macro to delete first nine characters in a cell for a row of data.
    By frebo in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-12-2013, 09:03 AM
  4. Replies: 2
    Last Post: 07-12-2011, 11:11 AM
  5. Macro to delete last 2 characters in a cell
    By rbichamp in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-20-2010, 01:36 PM
  6. Macro to Delete Last 11 Characters in each cell in column 1
    By smlaff01 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-28-2008, 01:17 PM
  7. Replies: 2
    Last Post: 09-17-2005, 11:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1