Link to home
Avatar of Robert Casaletta
Robert CasalettaFlag for United States of America

asked on

Data Entry Form

I am trying to create a data entry form in Excel and having intermittent issues with a run time 9 error subscript out of range. I have commented out the code and commented in the code several times getting it to work. My form is using combo boxes based on tables + text boxes. The tables are kept in 1 sheet and the target worksheet is titled WAV_Activity_Recap. I have not yet set a control button to display the user form.

Attached is my workbook. Any guidance is appreciated.
Avatar of Subodh Tiwari (Neeraj)
Subodh Tiwari (Neeraj)
Flag of India image

Your UserForm Initialize Event code assumes that all your tables are on the activesheet which is not the case so if you try to open the UserForm when the Tables Sheet is not the active sheet, the code is unable to find those tables on the activesheet.
To handle that issue, replace the UserForm_Initialize Event code with the following one...

Private Sub UserForm_Initialize()
Dim wsTables    As Worksheet
Set wsTables = Worksheets("Tables")
Me.cboFOC.List = wsTables.ListObjects("Table3").ListColumns(3).DataBodyRange.Value
Me.cboActivity.List = wsTables.ListObjects("Table1").ListColumns(3).DataBodyRange.Value
Me.cboRSN1.List = wsTables.ListObjects("Table12").ListColumns(2).DataBodyRange.Value
Me.cboRSN2.List = wsTables.ListObjects("Table12").ListColumns(2).DataBodyRange.Value
Me.cboRSN3.List = wsTables.ListObjects("Table12").ListColumns(2).DataBodyRange.Value
Me.cboRSN4.List = wsTables.ListObjects("Table12").ListColumns(2).DataBodyRange.Value
Me.cboRSN5.List = wsTables.ListObjects("Table12").ListColumns(2).DataBodyRange.Value
Me.cboDCT1.List = wsTables.ListObjects("Table2").ListColumns(3).DataBodyRange.Value
Me.cboDCT2.List = wsTables.ListObjects("Table2").ListColumns(3).DataBodyRange.Value
Me.cboDCT3.List = wsTables.ListObjects("Table2").ListColumns(3).DataBodyRange.Value
Me.cboDCT4.List = wsTables.ListObjects("Table2").ListColumns(3).DataBodyRange.Value
Me.cboDCT5.List = wsTables.ListObjects("Table2").ListColumns(3).DataBodyRange.Value
Me.cboOT1.List = wsTables.ListObjects("Table4").ListColumns(3).DataBodyRange.Value
Me.cboOT2.List = wsTables.ListObjects("Table4").ListColumns(3).DataBodyRange.Value
Me.cboOT3.List = wsTables.ListObjects("Table4").ListColumns(3).DataBodyRange.Value
Me.cboDLR_NBR.List = wsTables.ListObjects("Table5").ListColumns(1).DataBodyRange.Value
Me.txtBDate.Value = Format(Date, "Short Date")
Me.txtEDate.Value = Format(Date, "Short Date")
Me.TextBox1.Value = "WAV_Activity_Recap"
End Sub

Open in new window

Avatar of Robert Casaletta


I just tried the suggestion and still getting the run time 9 error....
When do you get that error?
Can you let me know the action you perform which leads to that error?
Okay, I added Worksheets("Tables").Activate after Set wsTables = Worksheets("Tables") and it seems to have worked. I will do some-more testing and keep you posted. If I may, when I select an item from the combo box, it does not appear but it does add to the targeted worksheet...any clues?
No, that is really not required i.e. you don't need to activate the Tables sheet if you correctly qualified the tables with the parent sheet.
See the attached with a button on Switchboard Sheet, click that button and the UserForm will be popped up without any error.

I didn't quite get your question, which ComboBox you are talking about? What do you mean by "it does not appear"?

Hmmmmm, when I was in my workbooks VBA section and running the form it did not work and gave the error. I can see that yours is working fine.

When I selected the consultant combo box and made a selection, nothing appears in the form.
Yes, the consultant and the activity comboboxes had the same issue.
I deleted both the comboboxes and inserted the new comboboxes with the default properties and they both work ok now.

WAV_Activity_Recap v2.xlsm
Any thoughts on why and should I redo all the boxes that do not work?

Also, thank you very much!!
Avatar of Subodh Tiwari (Neeraj)
Subodh Tiwari (Neeraj)
Flag of India image

Blurred text
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
K...again, appreciate the lesson...
Quick response and easy solution.
Glad your issue got resolved.