Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88868

Compile error: Sub or function not defined when filling and saving userform

$
0
0

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.

ImportUserform

The Add New Task Userform that is filled with data from the old sheet, and thne imported into new file

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)




Viewing all articles
Browse latest Browse all 88868


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>