I found some code on the web to create a survey form.
I modified it to create the option group that I want. In this case it makes a group in 3 rows
The problem is that instead of the group in each row linking to the cell next to it, they all link to the same cell
and the totals accumulate.
Sub SetupSurveyForm() 'code written by Dave Peterson 2005-10-27 'creates a survey form with option buttons Dim grpBox As GroupBox Dim optBtn As OptionButton Dim maxBtns As Long Dim myCell As Range Dim myRange As Range Dim wks As Worksheet Dim iCtr As Long Dim FirstOptBtnCell As Range Dim NumberOfQuestions As Long ' Dim myBorders As Variant ' myBorders = Array(xlEdgeLeft, xlEdgeTop, xlEdgeBottom, xlEdgeRight, _ xlInsideVertical, xlInsideHorizontal) maxBtns = 3 NumberOfQuestions = 3 Set wks = ActiveSheet With wks Set FirstOptBtnCell = .Range("c2") .Range("a:i").Clear ' With FirstOptBtnCell.Offset(-1, -1).Resize(1, maxBtns + 1) ' .Value = Array("q", "Sales", "Service", "Sales Engineer") ' .Orientation = 90 ' .HorizontalAlignment = xlCenter ' End With Set myRange = FirstOptBtnCell.Resize(NumberOfQuestions, 1) 'c2:questions + 1 ' With myRange.Offset(0, -1) ' .Formula = "=row()-" & myRange.Row - 1 ' .Value = .Value ' End With ' myRange.Offset(0, -3).Value = 1 'With myRange.Offset(0, -4) ' .FormulaR1C1 = "=rc[1]*rc[2]" 'End With '.Range("a1").Formula = "=sum(A2:A" & NumberOfQuestions + 1 & ")" ' With myRange.Offset(0, -4).Resize(, 4) ' For iCtr = LBound(myBorders) To UBound(myBorders) ' With .Borders(myBorders(iCtr)) ' .LineStyle = xlContinuous ' .Weight = xlThin ' .ColorIndex = xlAutomatic ' End With ' Next iCtr ' .HorizontalAlignment = xlCenter ' .VerticalAlignment = xlCenter ' End With 'myRange.Activate myRange.EntireRow.RowHeight = 28 'myRange.Resize(, maxBtns).EntireColumn.ColumnWidth = 4 myRange.EntireColumn.ColumnWidth = 32 'clean up existing junk .GroupBoxes.Delete .OptionButtons.Delete End With For Each myCell In myRange 'With myCell.Resize(1, maxBtns) With myCell '.Resize(1, maxBtns) Set grpBox = wks.GroupBoxes.Add(Top:=.Top, Left:=.Left, _ Height:=.Height, Width:=.Width) With grpBox .Caption = "" .Visible = True 'False End With End With For iCtr = 0 To maxBtns - 1 'create buttons 'With myCell.Offset(0, iCtr) With myCell '.Offset(0, iCtr) Select Case iCtr Case 0 Set optBtn = wks.OptionButtons.Add(Top:=.Top, Left:=94, _ Height:=.Height, Width:=.Width) Case 1 Set optBtn = wks.OptionButtons.Add(Top:=.Top, Left:=140, _ Height:=.Height, Width:=.Width) Case 2 Set optBtn = wks.OptionButtons.Add(Top:=.Top, Left:=190, _ Height:=.Height, Width:=.Width) End Select Select Case iCtr Case 0 optBtn.Caption = "Sales" Case 1 optBtn.Caption = "Service" Case 2 optBtn.Caption = "Service Engineer" End Select If iCtr = 0 Then With myCell.Offset(0, -2) optBtn.LinkedCell = .Address(external:=True) End With End If End With Next iCtr Next myCell End Sub
Running this code will create the option groups so you can see what I mean.
Can someone give me any ideas.
Thanks,
Scott