+ Reply to Thread
Results 1 to 16 of 16

macro to delete certain data in a cell

  1. #1
    Registered User
    Join Date
    09-09-2013
    Location
    South Africa
    MS-Off Ver
    Excel 2007
    Posts
    9

    Post macro to delete certain data in a cell

    any help with this one appreciated i am new to macro's and vba but came across a problem i need to delete certain data from all cells in column c to be specific numerical values in brackets and leave the text and the text in brackets alone.I tried text to columns as well but not working for me.

    any help ?

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: macro to delete certain data in a cell

    Sure, post a sample file with an exact representation of the data, 10-20 cells worth in column C. Make sure we see the original data and a mockup of the expected results.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: macro to delete certain data in a cell

    Hello james1432,

    Welcome to the Forum.

    While I am not sure what your data looks like, you may try the following Code. Just maybe it works for you.

    Please Login or Register  to view this content.
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  4. #4
    Registered User
    Join Date
    09-09-2013
    Location
    South Africa
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: macro to delete certain data in a cell

    Hello Winon

    Thank you for this code but it is not doing what i hoped it will as i needed to keep the text and delete the numerical values between the brackets your code keeps the numerical and deleted the text i needed tho , it kept the text that was in brackets here is a sample line with explanation what i need ,the code is close what i need so it seems you put me on the right track.

    Johannesburg (dap) (wtt musina) (103.-91000) the data differs tho on each cell in column c i need to keep all text and text between brackets and the numericals deleted. so it should look like this .....Johannesburg dap wtt musina and the rest deleted..
    Last edited by james1432; 09-13-2013 at 06:02 AM. Reason: typo's

  5. #5
    Registered User
    Join Date
    09-09-2013
    Location
    South Africa
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: macro to delete certain data in a cell

    here is column c data
    location
    Sandton, N1(dap)(10,-321)
    midrand,n3 (1233,-109)
    boksburg 6 km,(wtt musina)(10,-329)
    Sandton, N1(CROSSROADS)(10,-321)
    and here is how i would like the data displayed

    location
    Sandton,N1 dap
    midrand,n3
    boksburg 6 km wtt musina
    sandton,n1 crossroads

    Thank you in advanced..
    James
    Last edited by james1432; 09-13-2013 at 05:58 AM. Reason: typo

  6. #6
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: macro to delete certain data in a cell

    Hello james1432,

    To be honest, I do not know how to handle the variations,i.e.,

    Sandton, N1(dap)(10,-321)
    midrand,n3 (1233,-109)
    boksburg 6 km,(wtt musina)(10,-329)
    Sandton, N1(CROSSROADS)(10,-321)
    But I am sure that JBeaucaire has the solution.

    Hopefully, he will come to our rescue!

  7. #7
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,565

    Re: macro to delete certain data in a cell

    Assuming the data to removed is always the last bracketed data, this will do the job:

    Please Login or Register  to view this content.
    Regards,

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  8. #8
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: macro to delete certain data in a cell

    Assuming:

    1) Data is in column A starting at A2
    2) The data in parens with a negative number in it are to be discarded
    3) This parens group is always the last parens group



    MANUAL TEST - try this, if this works for you on a larger data set, I can give this to you in a macro format:

    B2: =LEFT(A2, SEARCH("(",A2)-1)
    C2: =MID(A2, SEARCH("(", A2)+1, SEARCH(")", A2)-SEARCH("(", A2)-1)
    D2: =B2&IF(ISNUMBER(SEARCH("-", C2)), "", " "& C2)

    Copy B2:D2 down the whole dataset, the answers are appearing in D2.

  9. #9
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: macro to delete certain data in a cell

    @ Trebor76,

    Thank you Robert, that is a very good macro.

    @ JBeaucaire,

    That is a very nice approach to avoid VBA. Thank you.

  10. #10
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,565

    Re: macro to delete certain data in a cell

    @ Winon

    Pleasure. Thanks for the kind feedback

    Robert

  11. #11
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: macro to delete certain data in a cell

    Hi, Robert,

    although Option Explicit is featured at the top I think this line is missing
    Please Login or Register  to view this content.
    Or at least the mentioning that itīs a public variable

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  12. #12
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: macro to delete certain data in a cell

    @ HaHoBe,

    You are very alert today! LOL

    However, I have tested Robert's Code and it works like a charm, regardless!

    Regards

  13. #13
    Registered User
    Join Date
    09-09-2013
    Location
    South Africa
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: macro to delete certain data in a cell

    Thank you JBeaucaire but Trebor76 macro is working like a charm for me.

  14. #14
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: macro to delete certain data in a cell

    Hello james1432,

    I am glad to hear that you could find use for my code somewhere else.

    Also thank you for adding to my Reputation.

    Baie dankie,

    Groete

  15. #15
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,565

    Re: macro to delete certain data in a cell

    Hi james1432 and Winon,

    Thank you both for your kind words and adding to my reputation

    Regards,

    Robert

  16. #16
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: macro to delete certain data in a cell

    I've marked this thread as SOLVED for you.
    Next time, select Thread Tools from the links above to mark a thread as SOLVED. Thanks.

+ 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] Macro to delete individual cell when data entered into another cell.
    By Thupp in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 05-19-2013, 03:49 PM
  2. 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
  3. [SOLVED] Need macro to delete part of the data in a cell
    By Ecruse in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 10-31-2012, 03:20 PM
  4. [SOLVED] Macro to delete selection of data if cell is certain value
    By Rogerj99 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-12-2012, 09:01 AM
  5. Macro, If cell A has data but cell B is empty delete complete row
    By stangz71 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-28-2011, 05:34 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