On my userform, I have several questions with Yes/No option buttons. When my Save/Close command button is executed, I have the following code to transfer the data:
Private Sub SaveClose_Click()
Dim ws1 As Worksheet: Set ws1 = Sheets("Dashboard")
Dim ws4 As Worksheet: Set ws4 = Sheets("LookupLists")
Dim ws3 As Worksheet: Set ws3 = Sheets("Data")
Dim emptyRow As Long
Dim x As Long, c As Long
Dim AutoNo As Long
'non-relevant code omitted for space
With ws3
AutoNo = Application.WorksheetFunction.Max(Sheet3.Columns(1))
AutoNo = AutoNo + 1
emptyRow = WorksheetFunction.CountA(ws3.Range("$C:$C")) + 1
.Cells(emptyRow, 1).Value = AutoNo
.Cells(emptyRow, 2).Value = Date
.Cells(emptyRow, 3).Value = cbo1.Value
.Cells(emptyRow, 4).Value = cbo2.Value
.Cells(emptyRow, 5).Value = txt1.Value
.Cells(emptyRow, 6).Value = cbo3.Value
.Cells(emptyRow, 7).Value = cbo4.Value
.Cells(emptyRow, 8).Value = txt2.Value
.Cells(emptyRow, 35).Value = cbo6.Value
.Cells(emptyRow, 36).Value = txt3.Value
.Cells(emptyRow, 9).Value = Day(txt2.Value)
.Cells(emptyRow, 10).Value = Month(txt2.Value)
.Cells(emptyRow, 11).Value = Year(txt2.Value)
'transfer option buttons data
If option1Y.Value = True Then
.Cells(emptyRow, 13).Value = 1
Else
.Cells(emptyRow, 13).Value = 2
End If
'option buttons 2 thru 10 omitted for space
If option11Y.Value = True Then
.Cells(emptyRow, 23).Value = 1
Else
.Cells(emptyRow, 23).Value = 2
End If
If option12Y.Value = True Then
.Cells(emptyRow, 24).Value = 1
Else
.Cells(emptyRow, 24).Value = 2
'transfer check boxes data
If chk11.Value = True Then .Cells(emptyRow, 12).Value = 1
If chk11.Value = False Then .Cells(emptyRow, 12).Value = 2
If chk2.Value = True Then .Cells(emptyRow, 25).Value = 2
If chk2.Value = False Then .Cells(emptyRow, 25).Value = 1
End If
End With
Unload Me
End Sub
This worked fine. But now I have had to change the last question (#12) to include not only Yes/No, but a third option button, "NA".
So I modified highlighted code above to the following (below) and changed nothing else, and I get a "Compile Error: End With without With" message. Any suggestions?
If option12Y.Value = True Then
.Cells(emptyRow, 24).Value = 1
If option12N.Value = True Then
.Cells(emptyRow, 24).Value = 2
If option12NA.Value = True Then
.Cells(emptyRow, 24).Value = 3
Bookmarks