+ Reply to Thread
Results 1 to 22 of 22

Find & Replace query

  1. #1
    Forum Contributor
    Join Date
    05-08-2009
    Location
    england
    MS-Off Ver
    Excel 2007
    Posts
    223

    Find & Replace query

    I'm just wondering, is there a way of coding a textbox to search for certain words and automatically changing their case...?

    An example,

    The user types out a paragraph in which he specifies a street, e.g. lime avenue, or a name e.g. roger federer, or an address, e.g. flat 14, new cut road, plymouth, sg4 3xb.

    Within this paragraph the user wants the above entries to appear as follows,

    LIME AVENUE, i.e. all UpperCase
    Roger FEDERER, i.e. First name ProperCase, lastname UpperCase
    FLAT 14, NEW CUT ROAD, PLYMOUTH, SG4 3XB. i.e. all UpperCase

    Can this be achieved?

    Some problems I forsee....

    A search could be created to look for "road" or "avenue" or "street".....but what about the word preceeding it, i.e. lime avenue, or what if there are more than one word, i.e. new cut road?

    Also, what if the name was "**** view", since you can also 'view' something...but wouldn't want every instance of view capitalised?

    In terms of the persons name...there could be an almost infinite number of permutations, as with address?

    Therefore what about the user placing some kind of indication with each word(s) of interest...something for the search to look out for, for example

    *lime avenue*, *flat 14, new cut road, plymouth, sg4 3xb*, and #roger federer#, where anything between *'s would be capitalised, and everything between #'s would be first word ProperCase, second word UpperCase...also where hyphenated words count as one, i.e. hunting-smythe.

    The find and replace feature in Word could be utilised once the text makes it into a document but the user would have to search each one in turn surely?


    Any thoughts?

  2. #2
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,835

    Re: Find & Replace query

    The only way of doing this would be to have a complete lookup list, perhaps in a text file, document or workbook (a textfile is probably the most versatile).
    Cheers,
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    Forum Contributor
    Join Date
    05-08-2009
    Location
    england
    MS-Off Ver
    Excel 2007
    Posts
    223

    Re: Find & Replace query

    This may be stating the obvious but when you say 'complete lookup list' do you mean you would need to list EVERY example that you would likely come across? As it is down to the inputter(s) to complete the textbox there could be any number of possibilities...

  4. #4
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,835

    Re: Find & Replace query

    Basically, yes; otherwise, how would your capitalisation routine be able to identify which words should be processed? A related issue you'll need to consider is how to handle strings that you do/don't want capitalised that are also found in larger strings that you want to process the opposite way...

  5. #5
    Forum Contributor
    Join Date
    05-08-2009
    Location
    england
    MS-Off Ver
    Excel 2007
    Posts
    223

    Re: Find & Replace query

    Hmmm..ok

    Everything is inputted into lowercase therefore you will only ever need to capitalise certain words or strings....

    I understand the logic of the lookup list but I can't see how it could be achieved, for the reasons we agree on above.

    Could there possibly be a way of 'flagging up' the relevant words/ strings within the text in order to give the routine something to look for, in the absence of a definitive list? Such as by placing a certain character at either end of the words or string to identify it, as suggested above.

  6. #6
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,835

    Re: Find & Replace query

    A possible workaround would be to put asterisks or something such either side of the characters/strings to be capitalised. Obviously, you'd want to ensure whatever delineation characters are chosen won't be used elsewhere. Some extra code could then be used to capitalise the intervening characters and delete the asterisks (or whatever).

  7. #7
    Forum Contributor
    Join Date
    05-08-2009
    Location
    england
    MS-Off Ver
    Excel 2007
    Posts
    223

    Re: Find & Replace query

    How might one go about doing that then, say by using *Firstname LASTNAME* and #ROAD NAME#, #FULL ADDRESS#. Case as shown. Stars and hash marks would not be used anywhere else.

  8. #8
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,835

    Re: Find & Replace query

    What I was thinking of was more along the lines of:
    *F*irstname *LASTNAME* and *ROAD NAME, FULL ADDRESS*.
    such that everything between a pair of control characters would be converted to uppercase. IMHO, though, it'd be better for users to capitalise the first letter of names rather than use the extra keystrokes for inserting asterisks.

  9. #9
    Forum Contributor
    Join Date
    05-08-2009
    Location
    england
    MS-Off Ver
    Excel 2007
    Posts
    223

    Re: Find & Replace query

    I agree, by the time you've highlighted the letter you might as well just do it. I've just thought of another too, the letter "i".

    I'll do some research and no doubt come back to you when I hit the wall.

  10. #10
    Forum Contributor
    Join Date
    05-08-2009
    Location
    england
    MS-Off Ver
    Excel 2007
    Posts
    223

    Re: Find & Replace query

    I have read around the subject and am familiar with the following,

    Please Login or Register  to view this content.
    However, this is geared to text found in the document and not the textbox that is being inputted and the selection element means you have to specify each word to look for. How can it be adapted to search for highlighted words in a range, in the textbox?

    EverythingI have found seems to be a variation on the above only.

  11. #11
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,835

    Re: Find & Replace query

    How can it be adapted to search for highlighted words in a range, in the textbox?
    If you mean the textbox in the userform, you can't.

  12. #12
    Forum Contributor
    Join Date
    05-08-2009
    Location
    england
    MS-Off Ver
    Excel 2007
    Posts
    223

    Re: Find & Replace query

    Oh, ok. Thats makes things a little clearer then....and I could do every section as I go, although it would make sense to do all sections together in one pass once all the information has been entered. It is only the main body of text to cover...no headers footers or anything like that.

  13. #13
    Forum Contributor
    Join Date
    05-08-2009
    Location
    england
    MS-Off Ver
    Excel 2007
    Posts
    223

    Re: Find & Replace query

    ok - it's straightforward to find & replace a single word in the document....however it gets a bit tedious when repeating for "x" number of words....which would also need hard coding....hence Macropods suggestion of a textfile to hold the data to refer to.

    Trouble is doing this to search for anything between two characters (which indicate that everything between needs to be replaced). I have seen many many instances where people have asked similar questions...n the one or two examples that appear to have solutions I simply get lost with some of the coding...and i must admit that my head is throbbing at the moment.

    I love the logic behind it all....but the language escapes me!

  14. #14
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,835

    Re: Find & Replace query

    The conversion isn't all that hard - really!!!
    Please Login or Register  to view this content.

  15. #15
    Forum Contributor
    Join Date
    05-08-2009
    Location
    england
    MS-Off Ver
    Excel 2007
    Posts
    223

    Re: Find & Replace query

    YES, unless of course you know what you're looking at!

  16. #16
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,835

    Re: Find & Replace query

    Quote Originally Posted by AndyE View Post
    YES, unless of course you know what you're looking at!
    Why unless???

  17. #17
    Forum Contributor
    Join Date
    05-08-2009
    Location
    england
    MS-Off Ver
    Excel 2007
    Posts
    223

    Re: Find & Replace query

    It doesn't matter.....I feel like a plummer trying to re-wire a house (having had a quick look at a manual)!!!

  18. #18
    Forum Contributor
    Join Date
    05-08-2009
    Location
    england
    MS-Off Ver
    Excel 2007
    Posts
    223

    Re: Find & Replace query

    I'm sorry...

    I kind of get what's going on, but not enough to be able to adapt it and incorporate it into my userform to suit my needs.

    Cheers though,

  19. #19
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,835

    Re: Find & Replace query

    So what is the code you're trying to get it to work with?

  20. #20
    Forum Contributor
    Join Date
    05-08-2009
    Location
    england
    MS-Off Ver
    Excel 2007
    Posts
    223

    Re: Find & Replace query

    As attached....
    Attached Files Attached Files

  21. #21
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,835

    Re: Find & Replace query

    In 'Sub cmdOK_Click' change:
    Selection.TypeText text:=TextBox1.text & vbCr & vbCr
    to:
    Selection.TypeText text:=BlockText(TextBox1.text) & vbCr & vbCr

    And re-code the sub I provided as a function:
    Please Login or Register  to view this content.
    Last edited by macropod; 09-14-2012 at 06:47 AM.

  22. #22
    Forum Contributor
    Join Date
    05-08-2009
    Location
    england
    MS-Off Ver
    Excel 2007
    Posts
    223

    Re: Find & Replace query

    As always....works fine....thank you.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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