Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-07-2014, 01:44 PM
frustrated teacher frustrated teacher is offline Delete starting number *) and delete Unneeded data in series Windows 7 64bit Delete starting number *) and delete Unneeded data in series Office 2010 64bit
Novice
Delete starting number *) and delete Unneeded data in series
 
Join Date: May 2014
Posts: 12
frustrated teacher is on a distinguished road
Default Delete starting number *) and delete Unneeded data in series

Hello friends,

It's another year of exams for my students and I am stuck trying to upload an exam to our antiquated system.

The exam system takes a particular format, I figured out how to upload the questions, but not the answers.

The questions are in plain text, no tables that I can see.

1) This is a question #1.
A) cat
B) dog
C) mouse
D) bird
Answer: C

11) This is a question #11.
A) cat
B) dog
C) mouse
D) bird
Answer: B

Ideally, I would like it to look like:

This is question #1. Answer: C) mouse



This is question #11. Answer: B) dog

What I've tried: I've used search functions

"Find what": ^13[0-9]
"Replace with": ^p

But that only deletes one number at a time and does not delete the ")"

Ive tried:
Code:
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
  .Text = "*\)" <<< and variations
  .Replacement.Text = ""
  .Forward = True
  .Format = False
  .MatchCase = False
  .MatchWholeWord = False
  .MatchWildcards = True
  .MatchSoundsLike = False
  .MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
But it doesnt seem to like the ")"

I know how to get RID of whole lines using a variation of:
Code:
Dim oRng As Word.Range
Dim oRngDelete As Word.Range
Set oRng = ActiveDocument.Range
With oRng.Find
  .Text = "word"
  While .Execute
    oRng.Select
    Set oRngDelete = ActiveDocument.Bookmarks("\Line").Range
    oRngDelete.Delete
  Wend
End With
End Sub
 
Sub ScratchMacroII()
Dim oRng As Word.Range
Set oRng = ActiveDocument.Range
With oRng.Find
  .Text = "word"
  While .Execute
  oRng.Paragraphs(1).Range.Delete
  Wend
End With
End Sub
But I'm still stuck on how to automatically "chose the right whole answer" and not just the letter of the right answer

Last edited by macropod; 12-07-2014 at 04:04 PM. Reason: Added code tags & formatting
Reply With Quote
  #2  
Old 12-07-2014, 03:29 PM
macropod's Avatar
macropod macropod is offline Delete starting number *) and delete Unneeded data in series Windows 7 64bit Delete starting number *) and delete Unneeded data in series Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

Without actually seeing the problem document, it can be difficult for anyone to provide specific advice on the issue. Can you attach a document to a post with some representative data (delete anything sensitive)? You do this via the paperclip symbol on the 'Go Advanced' tab at the bottom of this screen.

PS: When posting code, please use the code tags, indicated by the # button in the posting menu.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 12-07-2014, 04:25 PM
frustrated teacher frustrated teacher is offline Delete starting number *) and delete Unneeded data in series Windows 7 64bit Delete starting number *) and delete Unneeded data in series Office 2010 64bit
Novice
Delete starting number *) and delete Unneeded data in series
 
Join Date: May 2014
Posts: 12
frustrated teacher is on a distinguished road
Default

No problem! I mentioned in my post that it was just plain text with no tables, but I hope the attached file will make it clearer.

Here is a sample:

sampletext.docx
Reply With Quote
  #4  
Old 12-07-2014, 05:54 PM
macropod's Avatar
macropod macropod is offline Delete starting number *) and delete Unneeded data in series Windows 7 64bit Delete starting number *) and delete Unneeded data in series Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

Try:
Code:
Sub Demo()
Application.ScreenUpdating = False
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Format = False
    .Forward = True
    .Wrap = wdFindContinue
    .MatchWildcards = True
    .Text = "([0-9]@\)*^13)(*)(Answer:*^13)"
    .Replacement.Text = "\1\3\2"
    .Execute Replace:=wdReplaceAll
    .Text = "^13^13"
    .Replacement.Text = "^px^&"
    .Execute Replace:=wdReplaceAll
    .Text = "([0-9]@\)*Answer:*)([A-Z])*(\2\)*^13)*^13{2}"
    .Replacement.Text = "\1\3^p"
    .Execute Replace:=wdReplaceAll
  End With
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 12-07-2014, 06:44 PM
frustrated teacher frustrated teacher is offline Delete starting number *) and delete Unneeded data in series Windows 7 64bit Delete starting number *) and delete Unneeded data in series Office 2010 64bit
Novice
Delete starting number *) and delete Unneeded data in series
 
Join Date: May 2014
Posts: 12
frustrated teacher is on a distinguished road
Default

Wow! That's awesome. Sorry for the late reply. It works but it crashes my instance of word sometimes (that's probably a computer issue and not your macro issue).

Is it possible to just get the section of the macro that deletes the numbers? Or get a macro that just deletes the numbers along with the ")". I noticed it didnt delete the preceding numbers.

Again, thank you so much for your help.
Reply With Quote
  #6  
Old 12-07-2014, 06:53 PM
macropod's Avatar
macropod macropod is offline Delete starting number *) and delete Unneeded data in series Windows 7 64bit Delete starting number *) and delete Unneeded data in series Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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 wasn't apparent to me that you wanted to delete the question #s. To do that, change:
.Text = "([0-9]@\)*Answer:*)([A-Z])*(\2\)*^13)*^13{2}"
to:
.Text = "[0-9]@\) (*Answer:*)([A-Z])*(\2\)*^13)*^13{2}"
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Tags
delete number, find & replace, reorder

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete starting number *) and delete Unneeded data in series Macro Needed to delete Unwanted paragraphs in series frustrated teacher Word VBA 1 05-02-2014 03:32 PM
Macro Needed to Delete Unneeded Answers in Multiple Choice Format Question frustrated teacher Word VBA 6 05-02-2014 03:37 AM
Delete starting number *) and delete Unneeded data in series Delete table if cell has data So New2 This Word VBA 1 05-06-2013 09:00 PM
Delete option greyed out when trying to delete row 1 tpcervelo Excel 2 11-15-2011 06:48 AM
delete email message via blackberry and have it delete on my pop3 and my outlook Iamthestorm Outlook 2 10-28-2010 12:21 AM

Other Forums: Access Forums

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