+ Reply to Thread
Results 1 to 32 of 32

Replace Wildcard

  1. #1
    Registered User
    Join Date
    04-02-2020
    Location
    London
    MS-Off Ver
    365
    Posts
    22

    Replace Wildcard

    Hi All, im new here, and working on a macro which filters and sorts an excel spreadsheet.

    One of the sub routines it calls searches all the fields, and any text within "quote" is changed to #quote#

    Then when the user adds this text to word, they run a replace to change any text within #quote# to become Consolas font.

    The way it is done in word is like this:

    Replace all using this formula:
    Find what: (#)(*)(#)
    Click More
    Select Use Wildcards
    Replace with: \2 (with the cursor in the replace with field)
    Click Format
    Select Style
    Select Code Small Char (this is the consolas font)
    Click OK

    Ideally i want to do the process in excel instead, to save me the effort, so any text within #quote# is turned into Consolas font... I cant see how this is possible, as the wildcards option doesnt appear to be available, but i am wondering if i am missing something.... I usually do.

    Any help you would be gratefully received :

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,810

    Re: Replace Wildcard

    Assuming you are searching column A in Excel, this macro replaces the quotes with #:
    Please Login or Register  to view this content.
    Last edited by Mumps1; 04-02-2020 at 09:11 AM.
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,810

    Re: Replace Wildcard

    This macro will replace the quotes and change the font to Consolas:
    Please Login or Register  to view this content.
    Last edited by Mumps1; 04-02-2020 at 09:23 AM.

  4. #4
    Registered User
    Join Date
    04-02-2020
    Location
    London
    MS-Off Ver
    365
    Posts
    22

    Re: Replace Wildcard

    Wow that was quick, thank you. I have already replaced the quotes to #, so I just need to apply the font, I will try what you posted above and let you know. Thanks again.

  5. #5
    Registered User
    Join Date
    04-02-2020
    Location
    London
    MS-Off Ver
    365
    Posts
    22

    Re: Replace Wildcard

    Thank you. I have tried it. it works as I described, but I wasn't clear...

    I only want to change the font style within the #quote# the rest of the font in the cell should remains as is, probably calibri or arial. The end result would be one cell with two font types

    I want to remove the ## parts afterwards.

    I also want to search the entire worksheet ( but I can change that myself.)


    Thank you and sorry I wasn't clear initially.

    Initally a cell would look like this

    This is a test "some text" and some more words

    The end result would be ( I used Courier New below as consoles doesn't exist)


    This is a test some text and some more words

  6. #6
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,810

    Re: Replace Wildcard

    Try:
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    04-02-2020
    Location
    London
    MS-Off Ver
    365
    Posts
    22

    Re: Replace Wildcard

    Thanks, i will give that a go, I don't understand some of those commands, I will need to google them....

  8. #8
    Registered User
    Join Date
    04-02-2020
    Location
    London
    MS-Off Ver
    365
    Posts
    22

    Re: Replace Wildcard

    Hi, Thanks

    I hope you are having a good weekend.

    This is the code so far.

    Please Login or Register  to view this content.
    How would I change the code above so that it applies to any number of times consolas is required in a cell. -is this possible ?

    If a sentence has This is a test some text and some more words, and more in consolas ( or any number of consolas instances.

    I also wanted to then remove the # around the text. I tried a a rng.replace after the font is changed (rng.Characters) to remove the # around the text...



    but it resets the text which was set to consolas back to arial.

    How do I achieve this ? I'm guessing rng.replace isn't the correct command
    Last edited by benep123; 04-05-2020 at 10:33 AM.

  9. #9
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,810

    Re: Replace Wildcard

    Try:
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    04-02-2020
    Location
    London
    MS-Off Ver
    365
    Posts
    22

    Re: Replace Wildcard

    Cool thanks , i will give it a go !

  11. #11
    Registered User
    Join Date
    04-02-2020
    Location
    London
    MS-Off Ver
    365
    Posts
    22

    Re: Replace Wildcard

    Hi Mumps1,

    Thank you it works perfectly. I started trying create a macro to remove the # which is still around the words.

    The problem is it resets all the font style formatting.


    Please Login or Register  to view this content.
    So the font, which was like this:

    This is a test some text and some more words, and more in consolas

    Becomes

    This is a test some text and some more words, and more in consolas

    Can you suggest a way to modify the code above so it doesn't reset the formatting... ?

  12. #12
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,810

    Re: Replace Wildcard

    Try:
    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    04-02-2020
    Location
    London
    MS-Off Ver
    365
    Posts
    22

    Re: Replace Wildcard

    Thanks Mumps1,

    That did the trick, now the # is removed but the text isn't reset. Sorry I didn't get back to you sooner.

    For anyone that one day stumbles here and wants the final code it is here. It searches the entire worksheet, and looks for any text surrounded with ", changes it to # and then converts the text inside to consolas, then removes the #

    Please Login or Register  to view this content.

  14. #14
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,810

    Re: Replace Wildcard

    You are very welcome.

  15. #15
    Registered User
    Join Date
    04-02-2020
    Location
    London
    MS-Off Ver
    365
    Posts
    22

    Re: Replace Wildcard

    Hi Mumps1,

    I found a bug, in that if only one " is in the spreadsheet around some content, it crashes excel.

    I tried to be clever and got myself in a mess trying to write a macro where the excel would be searched, highlight the cell which has only one " and stop.... ( so that it could be fixed by either deleting or adding another ") but thinking about it overnight.... there is simple way.... i just don't know how .....Could you guide me in adding a line that says:

    if only one " is found - ignore. Maybe if an odd number of " are in a cell ignore that cell? I cant think of a more efficient way...


    Benep123

  16. #16
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,810

    Re: Replace Wildcard

    Try this macro. It will warn you if a cell has a missing quotation mark. The cell will be selected for you to modify. After each modification you will have to run the macro each time.
    Please Login or Register  to view this content.

  17. #17
    Registered User
    Join Date
    04-02-2020
    Location
    London
    MS-Off Ver
    365
    Posts
    22

    Re: Replace Wildcard

    Beautiful....!!!

    Thank you worked like a dream...

  18. #18
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,810

    Re: Replace Wildcard

    My pleasure.

  19. #19
    Registered User
    Join Date
    04-02-2020
    Location
    London
    MS-Off Ver
    365
    Posts
    22

    Re: Replace Wildcard

    Hi, I need some guidance again…
    This is the macro I was using… I tested it, and it worked, but now….
    These things happen.
    • It sometimes adds strange characters such as Â, in spaces.
    • It sometimes replaces ‘ in words like doesn’t to doesn’t
    • Sometimes it replaces “ with characters like “ and †and does not change the font.
    • It sometimes replaces the font with the desired font but leaves the #
    • And sometimes it works…
    I can’t identify this inconsistency

    Please Login or Register  to view this content.

  20. #20
    Registered User
    Join Date
    04-02-2020
    Location
    London
    MS-Off Ver
    365
    Posts
    22

    Re: Replace Wildcard

    I think one aspect was that when a curly quote is used ” as opposed to the regular quote " the macro doesn't like it.

    What confuses me is that the reason the macro changes everything to # before making changes was done to avoid this issue.

  21. #21
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,810

    Re: Replace Wildcard

    VBA does not recognize the "curly" form of the quotation mark as a valid quotation mark. Can you attach a copy of the file that is presenting these problems?

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

    Re: Replace Wildcard

    Quote Originally Posted by benep123 View Post

    Initally a cell would look like this

    This is a test "some text" and some more words

    The end result would be ( I used Courier New below as consoles doesn't exist)


    This is a test some text and some more words
    See if this is how you wanted.
    Please Login or Register  to view this content.
    If this doesn't work, need to see you workbook with before/after.

  23. #23
    Registered User
    Join Date
    04-02-2020
    Location
    London
    MS-Off Ver
    365
    Posts
    22

    Re: Replace Wildcard

    The random characters appear to be from the export, so not a problem with the macro (sorry macro)

    I cant attach for some reason... I get a white box, and nothing but the content of my test excel is this - in A1, A2, A3 and A4

    Adding text that works "disabled" this should not be a problem.
    The word "code code” displays a text but sometimes if the quotes are not the same like before the code “code” breaks and then everything breaks “code some-word” command.
    The word "code code” displays a text but sometimes if the quotes are not the same like before the code “code” breaks and then everything breaks “code some-word” command.
    The word "code code” displays a text but sometimes if the quotes are not the same like before the code “code” breaks and then everything breaks “code some-word” command.

    Which is exactly as the original but different text.... (and shorter) the different " marks seem to cause an issue.

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

    Re: Replace Wildcard

    To attach a workbook.
    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.

    See if this works.
    Please Login or Register  to view this content.
    Edit;
    Pattern has been changed.
    Last edited by jindon; 05-24-2020 at 10:15 AM.

  25. #25
    Registered User
    Join Date
    04-02-2020
    Location
    London
    MS-Off Ver
    365
    Posts
    22

    Re: Replace Wildcard

    Ok i have attached a dummy sample.

    Jindons macro crashes... and the original macro i posted changes the font but leaves the # in place.
    Attached Files Attached Files

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

    Re: Replace Wildcard

    Range.Character.Text method only works for the character length up to 256.

    Work around
    Please Login or Register  to view this content.

  27. #27
    Registered User
    Join Date
    04-02-2020
    Location
    London
    MS-Off Ver
    365
    Posts
    22

    Re: Replace Wildcard

    Thanks that works , im going to test it. Is there a character limitation with this workaround ?

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

    Re: Replace Wildcard

    No, but only concern is when you are applying multiple fonts in the same cell already, it would applies the font you originally set.

  29. #29
    Registered User
    Join Date
    04-02-2020
    Location
    London
    MS-Off Ver
    365
    Posts
    22

    Re: Replace Wildcard

    It appears to work very nicely. - Thank you thank you. I don't understand what you mean originally set? it appears to manage well with the two font types per cell. (it would never be more than that)

    My other issue relates to exporting the text into excel, the encoding type was UTF and it needed to be ANSI to deal with the curly quotes.

    Thank you again....

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

    Re: Replace Wildcard

    You can output as UTF-8 using ADO.Stream.

  31. #31
    Registered User
    Join Date
    04-02-2020
    Location
    London
    MS-Off Ver
    365
    Posts
    22

    Re: Replace Wildcard

    I am copying the content to Notepad and saving as ANSI coding - which works (so far)

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

    Re: Replace Wildcard

    OK,

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

+ 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. Replace a substring using wildcard in variable
    By Ausvirgo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-02-2019, 06:39 AM
  2. How to replace text with a wildcard?
    By Polymorpher in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-09-2014, 05:32 AM
  3. [SOLVED] Find: Using wildcard, but don't replace with wildcard
    By JimDandy in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-06-2013, 05:39 PM
  4. Replace Wildcard with Same Character
    By jmeggers in forum Excel General
    Replies: 6
    Last Post: 10-11-2011, 09:28 PM
  5. vba proc for a replace function using wildcard
    By wotadude in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-28-2010, 04:50 PM
  6. Wildcard Find and Replace
    By DaveSmith2020 in forum Excel General
    Replies: 5
    Last Post: 02-16-2009, 12:27 PM
  7. How to replace cells with wildcard?
    By betty77 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-06-2006, 01:55 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