I have a userform which can be used to add new tasks to an excel spreadsheet. However i want to add old tasks to the spreadsheet using the same userform. So i have created a macro that fills the userform with the data from a specified spreadsheet. The data is filled correctly into the userform, but when the data is saved from the userform into the spreadsheet i get the error "Compile error: Sub or function not defined" around the Controls function in the loop. This code i amusing is the same code that saves the inputs of a new task to the spreadhseet, so i dont understand why it is not working.
For Each Ctrl In userformorder
For a = 5 To 6
If Controls(Ctrl).Name = "SubTaskID" Then 'I get an error here regarding the Controls(Ctrl) part
col = IDCol
Controls(Ctrl).Value = extractws.Cells(a, col)
End If
If Controls(Ctrl).Name = "TextBoxsubtask" Then
col = SubTaskCol
Controls(Ctrl).Value = extractws.Cells(a, col)
End If
If Controls(Ctrl).Name = "ComboBoxDeliverableFormat" Then
col = DeliverableFormatCol
Controls(Ctrl).Value = extractws.Cells(a, col)
End If
Next Ctrl
End Sub
```
Code used to save the userform (Same as if the user was inputting the values themselves)