![]()  | 
	
		
			
  | 
	|||||||
  
 | 
	
| 
		 | 
	Thread Tools | Display Modes | 
| 
	 | 
| 
		 
			 
			#1  
			 
			
			
			
			
		 
		
	 | 
|||
		
		
  | 
|||
| 
		
	
		
		
			
			 
			
			Hi everyone, 
		
		
		
		
		
		
		
		
	
	I have a table (7 columns and 90 rows) with 90 questions each question in a row. In each row: the question comes in col 1, and in col 2 comes a radio button for Yes, and in col 3 a radio button for No. Then in only some of the last 4 cells on the right there is a "Y" letter. Those cells are either empty or have the letter Y in them. I named the option buttons as e.g. for first row/ question: OptionButton1y for the Yes button and OptionButton1n for the No. I also grouped each two option buttons in each row in a separate group called Q1, Q2....etc. (Note: creating those buttons made the doc take ages to load when first opened ! ) What I need to have is : When a NO option button is selected in any row (question), a macro looks if any of the last 4 cells in that row has a Y in it and if so to change the cell color shading to red. I need this to occur with each NO selection on each of the rows. I hope someone can kindly help me with this. Thanks so much in advance  | 
| 
		 
			 
			#2  
			 
			
			
			
			
		 
		
	 | 
||||
		
		
  | 
||||
| 
		
	
		
		
			
			 
			
			Post a sample document which illustrates how you have done the document.
		 
		
		
		
		
				__________________ 
		
		
		
		
		
	
	Andrew Lockton Chrysalis Design, Melbourne Australia  | 
| 
		 
			 
			#3  
			 
			
			
			
			
		 
		
	 | 
|||
		
		
  | 
|||
| 
		
	
		
		
			
			 
			
			Thanks so much Andrew 
		
		
		
			Here is attached a sample doc illustrating what I have and need achieved. Thanks so much in advance  | 
| 
		 
			 
			#4  
			 
			
			
			
			
		 
		
	 | 
|||
		
		
  | 
|||
| 
		
	
		
		
			
			 
			
			I'm not a big fan of ActiveX controls in Word.  I don't have time to figure out why the cell has to be selected, but this is doing what you want I think: 
		
		
		
		
Code: 
	Private Sub OptionButton1n_Change(): ChangeState OptionButton1n: End Sub
Private Sub OptionButton2n_Change(): ChangeState OptionButton2n: End Sub
Private Sub OptionButton3n_Change(): ChangeState OptionButton3n: End Sub
Private Sub OptionButton4n_Change(): ChangeState OptionButton4n: End Sub
Private Sub OptionButton5n_Change(): ChangeState OptionButton5n: End Sub
Private Sub OptionButton6n_Change(): ChangeState OptionButton6n: End Sub
Sub ChangeState(oOB As MSForms.OptionButton)
If oOB.Value = True Then
    ShadeCells Selection.Rows(1)
  Else
    ClearCells Selection.Rows(1)
  End If
lbl_Exit:
  Exit Sub
End Sub
Sub ShadeCells(oRow As Row)
Dim lngIndex As Long
  For lngIndex = 4 To 7
    If fcnCellText(oRow.Cells(lngIndex)) = "Y" Then
      oRow.Cells(lngIndex).Range.Select
      oRow.Cells(lngIndex).Range.Shading.BackgroundPatternColor = wdColorRed
    End If
  Next
lbl_Exit:
  Exit Sub
End Sub
Sub ClearCells(oRow As Row)
Dim lngIndex As Long
  For lngIndex = 4 To 7
    Selection.Rows(1).Cells(lngIndex).Range.Select
    Selection.Rows(1).Cells(lngIndex).Range.Shading.BackgroundPatternColor = wdColorAutomatic
  Next lngIndex
lbl_Exit:
  Exit Sub
End Sub
Function fcnCellText(oCell As Cell) As String
Dim oRng As Word.Range
  Set oRng = oCell.Range
  oRng.End = oRng.End - 1
  fcnCellText = oRng.Text
lbl_Exit:
  Exit Function
End Function
 | 
| 
		 
			 
			#5  
			 
			
			
			
			
		 
		
	 | 
|||
		
		
  | 
|||
| 
		
	
		
		
			
			 
			
			Thanks so much Greg for your kind help 
		
		
		
		
		
		
		
		
	
	The code worked great. It first threw a runtime error (this command is not available) and figured out I had to remove protection of the doc for it to work which is fine with me. I wonder if there is a better choice for having option buttons functionality (allowing only one answer be selected) that I can use instead especially as I mentioned before the document takes ages to load when the number of option buttons is big as in the case of this one (90 x 2 ). Quote: 
	
 Quote: 
	
 Thanks so much for all your kind help  | 
| 
		 
			 
			#6  
			 
			
			
			
			
		 
		
	 | 
|||
		
		
  | 
|||
| 
		
	
		
		
			
			 Code: 
	Select Case fcnCellText oRow.Cells(lngIndex)
  Case "Y", "Y*"
      oRow.Cells(lngIndex).Range.Select
      oRow.Cells(lngIndex).Range.Shading.BackgroundPatternColor = wdColorRed
 Case Else 'Do nonthing
 
 End Select
 | 
| 
		 
			 
			#7  
			 
			
			
			
			
		 
		
	 | 
|||
		
		
  | 
|||
| 
		
	
		
		
			
			 
			
			Thanks so much for your kind help always Greg. 
		
		
		
		
Quote: 
	
 I noticed that only my docs that have many option buttons (ActiveX Controls) are too slow to open and I was hoping I could have a macro to be able to use checkboxes instead and I came across your good article (linked below) but I'm afraid it only applies to Word 2010 and above as far as I understand so far from reading it ! I hope I'm wrong about this ![]() http://gregmaxey.com/word_tip_pages/...n_buttons.html Cheers  | 
| 
		 
			 
			#8  
			 
			
			
			
			
		 
		
	 | 
|||
		
		
  | 
|||
| 
		
	
		
		
			
			 
			
			Update: 
		
		
		
		
		
		
		
		
	
	Every document I have with a number of Active X Controls (Option Buttons mainly) is a big headache taking very long time to open ! I came across this nice solution MakeCheckBoxesExclusive macro to make checkboxes behave like Option Buttons. I tested it on the previously attached doc sample and worked fine (I kept the table and inserted frames in each row and still worked fine). However, the ShadeCells macro does not work anymore for it needs to first be tweaked to work with the checkboxes now instead of the OBs and, second, it needs the document be unprotected while the MakeCheckBoxesExclusive macro needs it protected to work !  | 
| 
		 
			 
			#9  
			 
			
			
			
			
		 
		
	 | 
||||
		
		
  | 
||||
| 
		
	
		
		
			
			 
			
			Again, you will need to post a sample doc - especially if you have included frames to complicate things further.
		 
		
		
		
		
		
		
			
				__________________ 
		
		
		
		
		
	
	Andrew Lockton Chrysalis Design, Melbourne Australia  | 
| 
		 
			 
			#10  
			 
			
			
			
			
		 
		
	 | 
|||
		
		
  | 
|||
| 
		
	
		
		
			
			 
			
			Thanks Andrew, 
		
		
		
			Here is an updated sample doc attached, thanks. I gave up using frames and the whole "checkbox with option button functionality" thing. I now have only checkboxes instead of option buttons, to make the document load faster. The kindly provided Greg's ShadeCells macro above needs now be re-written to work with checkboxes in place of option buttons ! I hope this is feasible with your great help everyone Thanks so much in advance  | 
| 
		 
			 
			#11  
			 
			
			
			
			
		 
		
	 | 
||||
		
		
  | 
||||
| 
		
	
		
		
			
			 
			
			Try this version of the code and set every checkbox to run MakeCheckBoxesExclusive on Exit 
		
		
		
		
		
		
			Code: 
	Sub MakeCheckBoxesExclusive()
  Dim oFF As FormField, rng As Range
  
    Set rng = Selection.Rows(1).Range
  
  If Selection.FormFields(1).CheckBox.Value Then
    For Each oFF In rng.FormFields
      oFF.CheckBox.Value = False
    Next oFF
    Selection.FormFields(1).CheckBox.Value = True
  End If
  
  'Must unprotect to change cell shading
  ActiveDocument.Unprotect Password:=""
    If rng.FormFields(2).CheckBox.Value = True Then
      ShadeCells rng.Rows(1)
    Else
      ClearCells rng.Rows(1)
    End If
  ActiveDocument.Protect Type:=wdAllowOnlyFormFields, noReset:=True, Password:=""
End Sub
Function ShadeCells(oRow As Row)
  Dim lngIndex As Long
  For lngIndex = 4 To 7
    Select Case fcnCellText(oRow.Cells(lngIndex))
      Case "Y"
        oRow.Cells(lngIndex).Range.Shading.BackgroundPatternColor = wdColorRed
      Case "Y*"
        oRow.Cells(lngIndex).Range.Shading.BackgroundPatternColor = wdColorBrown
     End Select
  Next
lbl_Exit:
  Exit Function
End Function
Function ClearCells(oRow As Row)
  oRow.Range.Shading.BackgroundPatternColor = wdColorAutomatic
End Function
Function fcnCellText(oCell As Cell) As String
  Dim oRng As Word.Range
  Set oRng = oCell.Range
  oRng.End = oRng.End - 1
  fcnCellText = oRng.Text
lbl_Exit:
  Exit Function
End Function
				__________________ 
		
		
		
		
		
	
	Andrew Lockton Chrysalis Design, Melbourne Australia  | 
| 
		 
			 
			#12  
			 
			
			
			
			
		 
		
	 | 
|||
		
		
  | 
|||
| 
		
	
		
		
			
			 
			
			Thanks so much Andrew  
		
		
		
		
		
		
		
		
	
	![]() Working great Thank you everyone for your wonderful kind support  
		 | 
 
 | 
	
	
| Thread Tools | |
| Display Modes | |
| 
		 | 
			 
			Similar Threads
		 | 
	||||
| Thread | Thread Starter | Forum | Replies | Last Post | 
		
		  How to remove background color in a table that isn't there but is there?
	 | 
	pintree3 | Word | 5 | 10-27-2014 10:23 AM | 
| Can't change table background color in the header in Microsoft Word 2011 | simeon1 | Word | 0 | 10-13-2014 11:07 AM | 
| Option Button selected will display text | ksigcajun | Word VBA | 7 | 07-14-2014 09:31 AM | 
		
		  Cell Background Color:  Base it on Content of Cell?
	 | 
	tatihulot | Excel | 4 | 08-14-2013 03:24 PM | 
| Change cell color everytime a value is selected in dropdown list | angelica_gloria | Excel | 4 | 01-27-2012 06:47 PM |