View Single Post
 
Old 03-12-2015, 10:40 AM
gmaxey gmaxey is offline Windows 7 32bit Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

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
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote