Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-02-2013, 06:57 PM
Chayes Chayes is offline Deleting lines above selected text Windows XP Deleting lines above selected text Office 2003
Advanced Beginner
Deleting lines above selected text
 
Join Date: May 2012
Posts: 79
Chayes is on a distinguished road
Default Deleting lines above selected text

Hi All



I've been trying construct some VBA to help tidy up some text.

As an example , I have lots of blocks of text like this :

BACKSTREET BOYS
SHAPE OF MY HEART
NEW UK JIVE LONG DELETED ORIGINAL 2000
63321BX19


BACKSTREET BOYS
QUIT PLAYING GAMES
EX UK JIVE ISSUE
259807BX223

I'm trying to highlight all lines containg 'BX' , and then delete the line above each of them.

It should then look like this :

BACKSTREET BOYS
SHAPE OF MY HEART
63321BX19


BACKSTREET BOYS
QUIT PLAYING GAMES
259807BX223


Grrateful for any help



Last edited by Chayes; 11-02-2013 at 06:59 PM. Reason: typo
Reply With Quote
  #2  
Old 11-02-2013, 08:55 PM
fumei fumei is offline Deleting lines above selected text Windows 7 64bit Deleting lines above selected text Office XP
Expert
 
Join Date: Jan 2013
Posts: 440
fumei is on a distinguished road
Default

One way (there are alternatives) would be:
Code:
Sub RemoveAboveBX()
Dim oPara As Paragraph
For Each oPara In ActiveDocument.Paragraphs
   If InStr(oPara.Range.Text, "BX") > 0 Then
      oPara.Previous.Range.Delete
   End If
Next
End Sub
Reply With Quote
  #3  
Old 11-02-2013, 09:47 PM
Chayes Chayes is offline Deleting lines above selected text Windows XP Deleting lines above selected text Office 2003
Advanced Beginner
Deleting lines above selected text
 
Join Date: May 2012
Posts: 79
Chayes is on a distinguished road
Default

Hi

Ok many thanks for that. It work perfecly first time.


BTW Just out of interest what change would you make to the code to bring the second line up onto the end of the first?

Perhaps with a dash so each would look like this:

BACKSTREET BOYS - SHAPE OF MY HEART
63321BX19


BACKSTREET BOYS - QUIT PLAYING GAMES
259807BX223




Grateful for your time and expertise.

Last edited by Chayes; 11-02-2013 at 09:48 PM. Reason: typo
Reply With Quote
  #4  
Old 11-02-2013, 09:50 PM
fumei fumei is offline Deleting lines above selected text Windows 7 64bit Deleting lines above selected text Office XP
Expert
 
Join Date: Jan 2013
Posts: 440
fumei is on a distinguished road
Default

Oh, and the above only really works if your "lines" are, in fact, paragraphs.
Reply With Quote
  #5  
Old 11-03-2013, 02:41 AM
macropod's Avatar
macropod macropod is offline Deleting lines above selected text Windows 7 32bit Deleting lines above selected text Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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

You could use a wildcard Find/Replace, where:
Find = ([!^13]@)^13([!^13]@^13)[!^13]@^13([!^13]@BX[!^13]@^13)
Replace = \1 - \2\3

No VBA required. If you really want VBA for this, simply record the above with the macro recorder.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #6  
Old 11-03-2013, 09:14 AM
Chayes Chayes is offline Deleting lines above selected text Windows XP Deleting lines above selected text Office 2003
Advanced Beginner
Deleting lines above selected text
 
Join Date: May 2012
Posts: 79
Chayes is on a distinguished road
Default

hi

Thanks for this. I had no joy , I'm afraid. i made a wildcard search using the search and replace codes you suggested , but it couldn't find any matches.

My page looks like this :

JON SMITH
37 ACACIA AVENUE
HUYTON
LIVERPOOL
CHESHIRE NN9 6LP




IGLESIAS JULIO
TO ALL THE GIRLS I`VE LOVED
118743BX65


BACKSTREET BOYS
MORE THAN THAT
27954BX236


Ideally after a search and replace it would look like this :

JON SMITH
37 ACACIA AVENUE
HUYTON
LIVERPOOL
CHESHIRE NN9 6LP




IGLESIAS JULIO - TO ALL THE GIRLS I`VE LOVED
118743BX65


BACKSTREET BOYS - MORE THAN THAT
27954BX236


Grateful for any advice.
Reply With Quote
  #7  
Old 11-03-2013, 01:33 PM
macropod's Avatar
macropod macropod is offline Deleting lines above selected text Windows 7 32bit Deleting lines above selected text Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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

The Find/Replace expressions I posted are designed to process the kind of data referred to in your first post. What you have now posted is different. To process that data, you could change the wildcard Find/Replace expressions to:
Find = ([!^13]@)^13([!^13]@^13)([!^13]@BX[!^13]@^13)
Replace = \1 - \2\3
or:
Find = ([!^13]@)^13([!^13]@^13[!^13]@BX[!^13]@^13)
Replace = \1 - \2
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #8  
Old 11-03-2013, 03:43 PM
Chayes Chayes is offline Deleting lines above selected text Windows XP Deleting lines above selected text Office 2003
Advanced Beginner
Deleting lines above selected text
 
Join Date: May 2012
Posts: 79
Chayes is on a distinguished road
Default

Hi

Ok thanks very much for this. It's working fine now , and I'm grateful your time and for your help.



Best Wishes
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to find text in between two characters and then format selected text? qcom Word 5 02-19-2015 11:23 PM
Deleting grid lines but keeping the axis lines CoffeeNut Excel 0 04-01-2013 01:50 PM
Importing selected lines from a txt file Pedgonc Excel 2 01-09-2013 12:44 PM
Deleting lines above selected text Deleting Lines Pulls Back Next Page SQLUSA Word 5 12-18-2012 03:53 PM
Deleting empty lines lostsoul62 Word 5 04-16-2012 04:55 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:44 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