I need help getting the following code to work:
'Saves data entered into the UserForm into the current row
Private Sub cmdSave_Click()
Dim ctl As Control
cmdSave.Enabled = True
cmdSearch.Enabled = True
cmdFirst.Enabled = True
cmdPrevious.Enabled = True
cmdClose.Enabled = True
cmdNext.Enabled = True
cmdLast.Enabled = True
Cells(r, 1).Select
For Each ctl In Me.Controls
If ctl.Name Like "tgo?" Then
If ctl.Value = True Then
Cells.Value = "Yes"
Else
Cells.Value = "No"
End If
End If
Next ctl
Cells(r, 1).Value = Me.txtCX1.Value
Cells(r, 2).Value = Me.txtCX2.Value
Cells(r, 3).Value = Me.txtCX3.Value
Cells(r, 4).Value = Me.txtCX4.Value
Cells(r, 5).Value = Me.txtCX5.Value
Cells(r, 6).Value = Me.cboCX6.Value
Cells(r, 7).Value = Me.txtCX7.Value
Cells(r, 8).Value = Me.tgoCX8.Value
Cells(r, 9).Value = Me.txtCX9.Value
Cells(r, 10).Value = Me.tgoCX10.Value
Cells(r, 11).Value = Me.tgoCX11.Value
Cells(r, 12).Value = Me.tgoCX12.Value
Cells(r, 13).Value = Me.txtCX13.Value
Cells(r, 14).Value = Me.txtCX14.Value
Cells(r, 15).Value = Me.txtCX15.Value
Cells(r, 16).Value = Me.txtCX16.Value
Cells(r, 17).Value = Me.txtCX17.Value
Cells(r, 18).Value = Me.txtCX18.Value
Cells(r, 19).Value = Me.txtCX19.Value
Cells(r, 20).Value = Me.txtCX20.Value
Cells(r, 21).Value = Me.txtCX21.Value
Cells(r, 22).Value = Me.txtCX22.Value
Cells(r, 23).Value = Me.txtCX23.Value
Cells(r, 24).Value = Me.txtCX24.Value
Cells(r, 25).Value = Me.txtCX25.Value
Cells(r, 26).Value = Me.tgoCX26.Value
Cells(r, 27).Value = Me.tgoCX27.Value
Cells(r, 28).Value = Me.tgoCX28.Value
Cells(r, 29).Value = Me.tgoCX29.Value
End Sub
Right now I can get what I want by doing this:
If Me.tgoCX8.Value = True Then
Cells(r, 8).Value = "Yes"
Else
Me.tgoCX8.Value = False
Cells(r, 8).Value = "No"
End If
But there are over 100 toggle buttons on my UserForm and I don't want to have to do that for every one. All my Toggle Buttons start with "tgo".
Thanks in advance
Bookmarks