Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 12-17-2017, 05:22 AM
gmayor's Avatar
gmayor gmayor is offline Automatically color the right options in red based on the answers provided Windows 10 Automatically color the right options in red based on the answers provided Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,144
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

If the document is exactly as you describe then the following should work. It does however rely on there being the same exact number of lines for each question and answer.
Code:
Sub MarkAnswers()
Dim oRng As Range, oAns As Range
Dim iQuest As Integer, iAns As Integer
Const sNumList As String = "0123456789"
    On Error GoTo lbl_Exit
    For iQuest = 1 To ActiveDocument.Paragraphs.Count Step 7 'step through the questions
        Set oRng = ActiveDocument.Paragraphs(iQuest).Range 'get the first paragraph of the question
        oRng.MoveEnd wdParagraph, 6 'Get the last empty paragraph of the block
        Set oAns = oRng.Paragraphs(6).Range 'set a range to the answer line
        oAns.Collapse 1 'collapse the range to its start
        oAns.MoveEndWhile sNumList 'move the end of the range to the end of the answer number
        If Len(oAns.Text) > 0 Then 'if there is a number on that line
            iAns = oAns.Text + 1 'add a 1 to that number - to correspond to the answer number
            oRng.Paragraphs(iAns).Range.Font.ColorIndex = wdRed ' colour that paragraph red
        End If
    Next iQuest 'and process the next question
lbl_Exit: 'clear up
    Set oRng = Nothing
    Set oAns = Nothing
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
 

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Change Color (Being provided between the two codes) bnyamin Word VBA 4 05-16-2017 10:55 PM
Macro- find and replace from preselected options based on frequency (like an Ad libs) blondie Word VBA 0 02-27-2017 01:41 PM
Automatically color the right options in red based on the answers provided Cell Color based on date jrfoley3 Excel 3 08-26-2016 10:49 PM
Automatically color the right options in red based on the answers provided Need to create a "Yes/NO" Form and based on answers prompt for informatin jaradani Word 4 10-12-2014 09:42 PM
Changing bar color automatically Mahmuz PowerPoint 0 03-28-2012 11:49 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:42 PM.


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