Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I am a teacher, and I need to edit a question bank document. The answers follow immediately after questions as following:

Question 1. Choose the best description of "X"
a. [description 1]
b. [description 2]
c. [description 3]
d. [description 4]

Answer c

Question 2. Choose...........

Answer d


The problem with the regular search and replace only works for the word 'Answer' but not the whole sentence to include the actual answer. I tried various macros but cannot find one to select the entire row. please help.

What I have tried:

Set myRange = ActiveDocument.Range(Start:=0, End:=Selection.End) 
For Each aWord In myRange.Words 
 If aWord.Text = "Answer " Then aWord.Delete 
Next aWord
Posted
Updated 20-May-19 21:04pm

The "Answer" consists of TWO "words".

When Text = "Answer", delete current word AND "next" word.

Then continue with next question.
 
Share this answer
 
Comments
Member 14393657 20-May-19 17:37pm    
Hi Gerry, thank you for your solution. How can I delete the next word followed by "Answer"? I cannot get my head round to do it because the next word varies to each question. Thanks a lot for your help.
Something like this:
Sub DeleteAnswers()
	Dim oRng As Word.Range
	Set oRng = ActiveDocument.Range
	With oRng.Find
		.Text = "Answer"
		While .Execute
			With oRng.Paragraphs(1).Range
			If .Characters(1) = "Answer" Then .Delete
			End With
		Wend
	End With
End Sub
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900