+ Reply to Thread
Results 1 to 13 of 13

Delete all text after character in cells

  1. #1
    Forum Contributor
    Join Date
    03-19-2019
    Location
    Essex, England
    MS-Off Ver
    Office 365
    Posts
    110

    Delete all text after character in cells

    Hi

    Thanks for looking. I have a data column with data validation drop down lists, the list shows 3 pieces of information for the user to select the right one, however when they select the right one I only want to display part of the text in the drop down list. I'm looking for a work change event to automate the process.

    I have seen and tried many ways but can't seem to get anything to work, probably because my VBA knowledge is limited!

    validation format is: OIL089---MA91173474---VCL15456656

    So what I need is just OIL089 showing and everything after the 9 should be deleted, or from the 1st hyphen onwards if you prefer.

    Any help you can offer would be appreciated, I'm getting nowhere.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Delete all text after character in cells

    Please provide your file with the data validation already set up then we can add the code. See yellow banner at the top of the page.

  3. #3
    Spammer
    Join Date
    10-23-2012
    Location
    Adelaide, Australia
    MS-Off Ver
    Excel 2003, Office 365
    Posts
    1,237

    Re: Delete all text after character in cells

    Try this... change "A:A" to the column your drop down is in.
    Please Login or Register  to view this content.
    Last edited by Croweater; 11-09-2020 at 08:53 PM.

  4. #4
    Forum Contributor
    Join Date
    03-19-2019
    Location
    Essex, England
    MS-Off Ver
    Office 365
    Posts
    110

    Re: Delete all text after character in cells

    Hi, thanks for the response.

    I should have explained myself clearer so apologies for that. The text shown above was just 1 line of the drop down list to show as an example, further examples shown below. What I need is everything from the first hyphen onwards deleted, so from the examples below I would just want OIL089, OIL1005 & OIL1028 left in the cell.


    OIL089---TMA0116757---VCL1839696
    OIL1005---HLCUTEM200100536---CCN20239
    OIL1028---590280937---CCN20367

  5. #5
    Spammer
    Join Date
    10-23-2012
    Location
    Adelaide, Australia
    MS-Off Ver
    Excel 2003, Office 365
    Posts
    1,237

    Re: Delete all text after character in cells

    Try this mod...
    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    03-19-2019
    Location
    Essex, England
    MS-Off Ver
    Office 365
    Posts
    110

    Re: Delete all text after character in cells

    Hi , i have attached the file as requested.

    FYI, the purpose of my request to show just the reference at the beginning is because I will use that ref to populate the rest of the row. The ref can appear multiple times in the list and so can the other text, this is just to help them select the correct one, there may be times when all the information in the drop down is the same but i will be highlighting the row if it is duplicated.

    The worksheet i'm working on is: 'Landed'

    The validation list is pulled from the 'RefBLandWarrant' tab, which is created in Power Query, (I have just merged the 3 cells).

    The rest of the row is populated from the 'Warrants' tab.

    -------

    I have no doubt there are better ways to do this, I have seen them online, but I have tried and failed at most of them! if you can can implement a better way of getting the sam eresult I am open to suggestions.

    Many thanks for looking into this for me.
    Last edited by Funkymonkey0073; 11-10-2020 at 06:33 PM.

  7. #7
    Forum Contributor
    Join Date
    03-19-2019
    Location
    Essex, England
    MS-Off Ver
    Office 365
    Posts
    110

    Re: Delete all text after character in cells

    Hi Croweater

    It works! so thank you very much for that, it really is appreciated

    As always there is a but, what I am working on I am hoping to use as a template, this particular one has all the refs beginning with 'OIL' however that 3 digit prefix changes on other spreadsheets which is why I was hoping to find a solution that removes all text after from the 1st hyphen, that way it would work on all spreadsheets regardless of the prefix.

    Of course I can just change the code on each template which wouldn't be a massive issue but If it could be avoided that would be my preference.

    Any help you can offer is appreciated but if your done with me now I understand, I am already happier than when I went to bed last night/this morning!

    Stuart

  8. #8
    Spammer
    Join Date
    10-23-2012
    Location
    Adelaide, Australia
    MS-Off Ver
    Excel 2003, Office 365
    Posts
    1,237

    Re: Delete all text after character in cells

    So just remove the first 'IF' statement. This will leave everything to the left of the first hyphen regardless.

    Please Login or Register  to view this content.

  9. #9
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,913

    Re: Delete all text after character in cells

    Perhaps this:

    Please Login or Register  to view this content.
    Rory

  10. #10
    Valued Forum Contributor
    Join Date
    06-27-2010
    Location
    sYRIA
    MS-Off Ver
    Excel 2013
    Posts
    669

    Re: Delete all text after character in cells

    Hi,
    you may try
    Please Login or Register  to view this content.

  11. #11
    Forum Contributor
    Join Date
    03-19-2019
    Location
    Essex, England
    MS-Off Ver
    Office 365
    Posts
    110

    Re: Delete all text after character in cells

    Perfect, thank you so much.

    Stuart

  12. #12
    Forum Contributor
    Join Date
    03-19-2019
    Location
    Essex, England
    MS-Off Ver
    Office 365
    Posts
    110

    Re: Delete all text after character in cells

    Also worked, so thank you very much.

    I have no idea what the difference is between the 2 so not sure if one is better than the other but they both appear to produce the same result.

    Thanks again

  13. #13
    Forum Contributor
    Join Date
    03-19-2019
    Location
    Essex, England
    MS-Off Ver
    Office 365
    Posts
    110

    Re: Delete all text after character in cells

    Hi many thanks, I have 2 working options above which I have implemented. Thanks for the response though, its appreciated.

    Stuart

+ 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] VB Code to delete certain character in cells
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-16-2018, 01:29 PM
  2. [SOLVED] VB Code to delete blank character before and/or after text in cell
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-09-2018, 12:54 PM
  3. Code to delete text left of a specific character
    By Yoshi64 in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 10-21-2014, 05:38 AM
  4. Replies: 0
    Last Post: 10-10-2013, 07:43 AM
  5. Delete rows if cells have character(s)...
    By elsoung in forum Excel General
    Replies: 8
    Last Post: 10-04-2012, 06:29 PM
  6. How to Delete Text Before First Occurrence Of Character?
    By JimMW in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-09-2012, 11:06 AM
  7. Macro to find character and delete all text in cell after the character
    By SpencerRichman in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-01-2012, 06:08 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