+ Reply to Thread
Results 1 to 8 of 8

Replace characters in range if conditions are met

  1. #1
    Registered User
    Join Date
    11-16-2018
    Location
    US
    MS-Off Ver
    2013
    Posts
    4

    Replace characters in range if conditions are met

    I'm a complete rookie when it comes to VBA but am fairly experienced with excel. I know the nature of the argument I want to make but am not very good with syntax in VBA

    Here's what i want to do, all of the cells in range I:I contain text. The text in many of these cells begins with "(x)" where x is a 1-5 digit number. I want to erase such occurrences. It is possible that some of the text strings will not start with bracketed numbers but will have text in brackets elsewhere in the string. It is also possible that both bracketed occurrences will occur: the text string begins with "(x)" and has other text in brackets later in the string.

    Because I don't want to replace text within brackets that's later in the string and since it is possible this will be the first occurrence of text within brackets, I can't simply use replace "(x)" even if I limited it to the first occoruance of "(x)".

    The solution I thought of, if I were writing this as a formula in another cell, is

    =IF(FIND(")",I581)<=7,RIGHT(I1,LEN(I1)-FIND(")",I1)),I1)

    The idea behind this is that in the cases I want to remove the brackets and text, the first occurrence of the right bracket ")" will always be the 7th character or less. I would like to achieve this result to the entire range using a macro.

    Thanks

  2. #2
    Valued Forum Contributor
    Join Date
    11-28-2015
    Location
    indo
    MS-Off Ver
    2016 64 bitt
    Posts
    1,256

    Re: Replace characters in range if conditions are met

    Please Login or Register  to view this content.
    Last edited by daboho; 11-16-2018 at 07:09 PM.

  3. #3
    Valued Forum Contributor
    Join Date
    11-28-2015
    Location
    indo
    MS-Off Ver
    2016 64 bitt
    Posts
    1,256

    Re: Replace characters in range if conditions are met

    this work for me
    Please Login or Register  to view this content.
    "ThankyouFor Attention * And Your Help!!"

  4. #4
    Registered User
    Join Date
    11-16-2018
    Location
    US
    MS-Off Ver
    2013
    Posts
    4

    Re: Replace characters in range if conditions are met

    Thank you for the replies. My apologies for not replying sooner, I haven't been able to get back to this until now.

    Neither macro seems to be working. The first one causes an error "run-time error '5': Invalid Procedure Call or Argument"

    The 2nd one runs but doesn't seem to remove the bracketed text string.

    I don't know if this helps but I thought of a better way to express my argument as a formula, I also caught an error in my original example. First, my original formula references cell I581, this was an error and should have been I1. Second, I think it's better to express the argument as: =IF(FIND("(",I1)=1,RIGHT(I1,LEN(I1)-FIND(")",I1)),I1)

    Thanks for your help

  5. #5
    Valued Forum Contributor
    Join Date
    11-28-2015
    Location
    indo
    MS-Off Ver
    2016 64 bitt
    Posts
    1,256

    Re: Replace characters in range if conditions are met

    Give sample workbook

  6. #6
    Registered User
    Join Date
    11-16-2018
    Location
    US
    MS-Off Ver
    2013
    Posts
    4

    Re: Replace characters in range if conditions are met

    I think that the firewall at my work may be preventing me from uploading a a file directly.

    I also tried to post a google drive link to a sample workbook but am getting an error message that I need to post more times before I'm allowed to post links

    drive.google.com/file/d/1FQ3H1zdcQMyeAl-8NbFCQAc7Bjqa0nVs/view?usp=sharing

    I removed the https// from the link so that it would allow me to post

  7. #7
    Forum Expert
    Join Date
    04-01-2013
    Location
    East Auckland
    MS-Off Ver
    Excel 365
    Posts
    1,343

    Re: Replace characters in range if conditions are met

    See if this gets you closer

    Please Login or Register  to view this content.
    If you want something done right... find a forum and ask an online expert.

    Time flies like an arrow. Fruit flies like a banana.

  8. #8
    Registered User
    Join Date
    11-16-2018
    Location
    US
    MS-Off Ver
    2013
    Posts
    4

    Re: Replace characters in range if conditions are met

    That appears to be working. Thank you for your help!

+ 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. Replies: 1
    Last Post: 11-12-2018, 04:20 PM
  2. [SOLVED] Replace accented characters in worksheet name to regular characters
    By kingsdime29x in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-18-2017, 10:59 AM
  3. [SOLVED] find and replace to not replace characters found as wildcards
    By sabutler4 in forum Excel General
    Replies: 4
    Last Post: 07-03-2013, 06:48 PM
  4. Macro to replace European characters with non "special" English characters?
    By johanna0507 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-19-2012, 09:13 AM
  5. Replace certain characters
    By brownbread in forum Excel General
    Replies: 1
    Last Post: 06-18-2010, 12:00 PM
  6. Replace characters
    By ajaykgarg in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-05-2010, 07:33 PM
  7. fin/replace and keep some characters
    By skullk in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 09-11-2009, 10:31 AM

Tags for this Thread

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