Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-18-2017, 08:08 AM
jeffreybrown jeffreybrown is offline Add a return between two square brackets Windows Vista Add a return between two square brackets Office 2007
Expert
Add a return between two square brackets
 
Join Date: Apr 2016
Posts: 673
jeffreybrown has a spectacular aura aboutjeffreybrown has a spectacular aura about
Default Add a return between two square brackets

I have multiple instances of square brackets that I need to add a return...



Can this be done with a macro?

Before-
[Proverbs 4:26 NASB] [26] Watch the path of your feet And all your ways will be established.
[Proverbs 18:19 NASB] [19] A brother offended is harder to be won than a strong city, And contentions are like the bars of a citadel.
[Proverbs 11:29 NASB] [29] He who troubles his own house will inherit wind, And the foolish will be servant to the wisehearted.

After-
[Proverbs 4:26 NASB]
[26] Watch the path of your feet And all your ways will be established.
[Proverbs 18:19 NASB]
[19] A brother offended is harder to be won than a strong city, And contentions are like the bars of a citadel.
[Proverbs 11:29 NASB]
[29] He who troubles his own house will inherit wind, And the foolish will be servant to the wisehearted.
Reply With Quote
  #2  
Old 02-18-2017, 08:55 AM
slaycock slaycock is offline Add a return between two square brackets Windows 7 64bit Add a return between two square brackets Office 2013
Expert
 
Join Date: Sep 2013
Posts: 256
slaycock is on a distinguished road
Default

You gave no feedback about the last code you received so why should anyone help you this time.
Reply With Quote
  #3  
Old 02-18-2017, 09:55 AM
Pecoflyer's Avatar
Pecoflyer Pecoflyer is offline Add a return between two square brackets Windows 7 64bit Add a return between two square brackets Office 2010 64bit
Expert
 
Join Date: Nov 2011
Location: Brussels Belgium
Posts: 2,779
Pecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant future
Default

@slaycock
As your (unfriendly) remark might be understandable in some cases (and perhaps even correct in this case), I would suggest you take some time to investigate the person you are offensive with in the future

Jeff has been a great help on this forum ( I know it mostly from Excel and other forums), providing good answers and also getting more than his share of OP's not giving any feedback, not thanking him, etc.. (I know the feeling too after more than 10k posts on various forums...)
AFAIK, he never made any remarks in the sense you did although I can easily imagine he has been frustrated many times.
I do not know how well you are acquainted with free forums, but in this case you seem to be heavily overreacting and possibly hurting someone who is a great help.
May I suggest, in the future, that you PM the member to understand why he gave no feedback?
Cheers
__________________
Did you know you can thank someone who helped you? Click on the tiny scale in the right upper hand corner of your helper's post
Reply With Quote
  #4  
Old 02-18-2017, 10:32 AM
slaycock slaycock is offline Add a return between two square brackets Windows 7 64bit Add a return between two square brackets Office 2013
Expert
 
Join Date: Sep 2013
Posts: 256
slaycock is on a distinguished road
Default

I stand corrected.

The answer John is looking for is to use Find and Replace with wildcards

Search for ([\]])([\[]) and replace with \1^p\1.

It looks complicated because both [ and ] have to be escaped by preceding them with the \

The replace box refers to fiels which are defined by everything between 9 and 0. The search has two such fields.

the ^p is the replace special symbol for a pararaph marker/ NOTE that ^p cannot be used in the search box, you need to use ^013 instead.

If you were doing this by a macro then

.find.text="([\]])([\[])"
.replacement.text="\1^p\2"
Reply With Quote
  #5  
Old 02-18-2017, 10:56 AM
jeffreybrown jeffreybrown is offline Add a return between two square brackets Windows Vista Add a return between two square brackets Office 2007
Expert
Add a return between two square brackets
 
Join Date: Apr 2016
Posts: 673
jeffreybrown has a spectacular aura aboutjeffreybrown has a spectacular aura about
Default

Thank you both Pecoflyer and slaycock...

@slaycock,

I'm stepping out right now with the grandkids to enjoy the day, so I will test this later with the appropriate feedback.
Reply With Quote
  #6  
Old 02-18-2017, 03:54 PM
jeffreybrown jeffreybrown is offline Add a return between two square brackets Windows Vista Add a return between two square brackets Office 2007
Expert
Add a return between two square brackets
 
Join Date: Apr 2016
Posts: 673
jeffreybrown has a spectacular aura aboutjeffreybrown has a spectacular aura about
Default

Hi slaycock,

Didn't quite get the results I expected. First, it does not handle the space between the open and close square bracket. I removed the space and the f/r did run, but was hoping the find and replace could pick up the ] space [ pattern.

However, by removing the space, one of the open square brackets gets changed to a close square bracket on the new line instead of the results in post #1.

[Proverbs 4:26 NASB]
]26] Watch the path of your feet And all your ways will be established.
[Proverbs 18:19 NASB]
]19] A brother offended is harder to be won than a strong city, And contentions are like the bars of a citadel.
[Proverbs 11:29 NASB]
]29] He who troubles his own house will inherit wind, And the foolish will be servant to the wisehearted.
Reply With Quote
  #7  
Old 02-19-2017, 03:34 AM
slaycock slaycock is offline Add a return between two square brackets Windows 7 64bit Add a return between two square brackets Office 2013
Expert
 
Join Date: Sep 2013
Posts: 256
slaycock is on a distinguished road
Default

My Apologies there is a typo in the first replace text (That's happening a lot at the moment as I have a new keyboard)

\1^p\1

should read
\1^p\2

which I did get right further down the page. My old eyes missed the space between the ] and [

The revised search would be

([\]])(*)([\[])

Personally I find the search text quite hard to scan, particularly on my hi res monitor where the search and replace dialog box is tiny.

So on reflection an easier to read version would have been

([^091])(*)([^093])

where 091 and 093 are the decimal ascii codes for [ and ].

You can get more information on find and replace using wildcards by clicking the ? on the find and replace dialog box and first looking under

Search by using wildcards

and then

Find and replace text by using regular expressions (Advanced)
Reply With Quote
  #8  
Old 02-19-2017, 07:49 AM
jeffreybrown jeffreybrown is offline Add a return between two square brackets Windows Vista Add a return between two square brackets Office 2007
Expert
Add a return between two square brackets
 
Join Date: Apr 2016
Posts: 673
jeffreybrown has a spectacular aura aboutjeffreybrown has a spectacular aura about
Default

Thanks slaycock for the additional help...

Using...

Find What: ([^091])(*)([^093]) >> Use Wildcard checked
Replace: \1^p\2

I get six replacement where I would only expect three

The following is what is returned...

[
Colossians 3:19 NASB [
19 Husbands, love your wives and do not be embittered against them.

[
Ephesians 3:21 NASB [
21 to Him be the glory in the church and in Christ Jesus to all generations forever and ever. Amen.

[
Ephesians 5:33 NASB [
33 Nevertheless, each individual among you also is to love his own wife even as himself, and the wife must see to it that she respects her husband.

Is it possible to just look for the [ followed by a number and generate the return just before that string?
Reply With Quote
  #9  
Old 02-19-2017, 08:24 AM
slaycock slaycock is offline Add a return between two square brackets Windows 7 64bit Add a return between two square brackets Office 2013
Expert
 
Join Date: Sep 2013
Posts: 256
slaycock is on a distinguished road
Default

What you are seeing is the ongoing demonstration of my lack of checking due to haste (I'm actually working at home this weekend fighting a deadline).

What has happened is that we have two errors. One in the find field and one in the replace field.

In the find field we have the ][ the wrong way round. The find field should be
([^093])(*)([^091] not ([^091])(*)([^093]


The error in the replace field comes adding the (*) to the search text. We now have three fields defined by () (Smacks head on wall several times because checking back I can see that my attempt at () in our earlier discussion came out as 9 0. This is because my new keyboard has the number and symbols the wrong way round so my brain types ( but my reflexes type 9 because 9 is above the ( on my new (soon to be ebayed) keyboard)

By inserting the (*) your bracket fields have now become fields 1 and 3. By using fields 1 and 2 in the replace text we are replacing the found text with the [ (in this case) and the text found by the (*) (which in this case is everything between the [ and ])



So changing the replace text to \1^p\3 should now get us to the place where you want to be.
Reply With Quote
  #10  
Old 02-19-2017, 12:35 PM
jeffreybrown jeffreybrown is offline Add a return between two square brackets Windows Vista Add a return between two square brackets Office 2007
Expert
Add a return between two square brackets
 
Join Date: Apr 2016
Posts: 673
jeffreybrown has a spectacular aura aboutjeffreybrown has a spectacular aura about
Default

Now this time it added the return, but deleted the words after the verse number except for the last verse...

Results:

[Colossians 3:19 NASB]
[19]
[Ephesians 3:21 NASB]
[21]
[Ephesians 5:33 NASB]
[33] Nevertheless, each individual among you also is to love his own wife even as himself, and the wife must see to it that she respects her husband.

...and on ([^093])(*)([^091]) I added the last paranthesis
Reply With Quote
  #11  
Old 02-19-2017, 02:05 PM
macropod's Avatar
macropod macropod is offline Add a return between two square brackets Windows 7 64bit Add a return between two square brackets Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

It seems to me you could use a ordinary Find/Replace, where:
Find = ]^w[
Replace = ]^p[
or
Replace = ]^l[
depending on whether you want to use a paragraph break or line break.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #12  
Old 02-19-2017, 03:15 PM
jeffreybrown jeffreybrown is offline Add a return between two square brackets Windows Vista Add a return between two square brackets Office 2007
Expert
Add a return between two square brackets
 
Join Date: Apr 2016
Posts: 673
jeffreybrown has a spectacular aura aboutjeffreybrown has a spectacular aura about
Default

Thank you Paul, works great.
Reply With Quote
  #13  
Old 02-20-2017, 03:03 AM
slaycock slaycock is offline Add a return between two square brackets Windows 7 64bit Add a return between two square brackets Office 2013
Expert
 
Join Date: Sep 2013
Posts: 256
slaycock is on a distinguished road
Default

Quote:
Thank you Paul, works great.
<Sigh> I wish I did!! Apologies for all the confusion. But a least it was an example of what a tangle you can get yourself into with careless and poorly thought through wildcard searches.

I'l now go stand in the corner until the end of class.

And whilst I was doing that I came up with the idea of following up the search and replace using ]^w[ with a second one using just ][ to catch any cases where there is no white space between the ] and [ of interest
Reply With Quote
  #14  
Old 02-20-2017, 07:27 AM
jeffreybrown jeffreybrown is offline Add a return between two square brackets Windows Vista Add a return between two square brackets Office 2007
Expert
Add a return between two square brackets
 
Join Date: Apr 2016
Posts: 673
jeffreybrown has a spectacular aura aboutjeffreybrown has a spectacular aura about
Default

In the end, this macro does exactly as needed...

Thanks to all...

Code:
Sub CleanUpBrakets()
    Application.ScreenUpdating = False
    With ActiveDocument.Range.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchWildcards = False
        .text = "]^w["
        .Replacement.text = "]^l["
        .Execute Replace:=wdReplaceAll
        .text = "^w["
        .Replacement.text = "^l["
        .Execute Replace:=wdReplaceAll
    End With
    Application.ScreenUpdating = True
End Sub
Reply With Quote
  #15  
Old 02-20-2017, 05:28 PM
macropod's Avatar
macropod macropod is offline Add a return between two square brackets Windows 7 64bit Add a return between two square brackets Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

In that case, all you really needed was:
Code:
Sub CleanUpBrakets()
    Application.ScreenUpdating = False
    With ActiveDocument.Range.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Wrap = wdFindContinue
        .Format = False
        .MatchWildcards = False
        .Text = "^w["
        .Replacement.text = "^l["
        .Execute Replace:=wdReplaceAll
    End With
    Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Add a return between two square brackets Bold numbers between square brackets jeffreybrown Word 4 02-13-2017 04:32 PM
Add a return between two square brackets Help with: Replace and reformat numbers inside square brackets johnbrowny Word 1 02-13-2016 06:45 PM
Gray square brackets waldux Word 8 09-25-2013 04:14 PM
Add a return between two square brackets square brackets and grey background – why? eNGiNe Word 2 11-21-2012 01:06 AM
Add a return between two square brackets Filled square daksein Drawing and Graphics 4 06-21-2011 02:36 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:38 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft