View Single Post
 
Old 05-02-2024, 04:59 AM
Dobracik1 Dobracik1 is offline Windows 11 Office 2021
Novice
 
Join Date: May 2024
Posts: 2
Dobracik1 is on a distinguished road
Default VBA code to remove empty rows above the specific sentence

Hi all :-)


I'm a new one in Word developing and would like to ask for a small support.

I do have template, when running a mailemerge from one excel column, whether do have a complex concatenate formula ( out of 10 columns behind).

What I need, as after mail emerge I do have a lot of empty rows. Is there any change or possibility to have some sort of VBA code that will automatically remove all empty rows between this sentences, example and will keep only 1 empty row?



"You are in amid of this agreement."

"You are in the end of this agreement. "

I have found the following code, but this will delete all empty rows in document. Is it possible to update it for above condition?
Quote:
Sub Deleemptyparagraphs()
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^p^p"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
.MatchFuzzy = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub

Thanks,
Andy
Reply With Quote