We help IT Professionals succeed at work.

Data Entry Form

Medium Priority
86 Views
Last Modified: 2020-03-17
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.
WAV_Activity_Recap.xlsm
Comment
Watch Question

Subodh Tiwari (Neeraj)Excel & VBA Expert
CERTIFIED EXPERT
Most Valuable Expert 2018
Awarded 2015

Commented:
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

Robert CasalettaManager, Warranty Performance

Author

Commented:
I just tried the suggestion and still getting the run time 9 error....
Subodh Tiwari (Neeraj)Excel & VBA Expert
CERTIFIED EXPERT
Most Valuable Expert 2018
Awarded 2015

Commented:
When do you get that error?
Can you let me know the action you perform which leads to that error?
Robert CasalettaManager, Warranty Performance

Author

Commented:
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?
Subodh Tiwari (Neeraj)Excel & VBA Expert
CERTIFIED EXPERT
Most Valuable Expert 2018
Awarded 2015

Commented:
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"?

WAV_Activity_Recap.xlsm
Robert CasalettaManager, Warranty Performance

Author

Commented:
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.
Subodh Tiwari (Neeraj)Excel & VBA Expert
CERTIFIED EXPERT
Most Valuable Expert 2018
Awarded 2015

Commented:
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
Robert CasalettaManager, Warranty Performance

Author

Commented:
Any thoughts on why and should I redo all the boxes that do not work?

Also, thank you very much!!
Excel & VBA Expert
CERTIFIED EXPERT
Most Valuable Expert 2018
Awarded 2015
Commented:
Replacing a non working control with a new one is not a big deal specially when you don't know what wrong you did with that control.
Robert CasalettaManager, Warranty Performance

Author

Commented:
K...again, appreciate the lesson...
Robert CasalettaManager, Warranty Performance

Author

Commented:
Quick response and easy solution.
Subodh Tiwari (Neeraj)Excel & VBA Expert
CERTIFIED EXPERT
Most Valuable Expert 2018
Awarded 2015

Commented:
Glad your issue got resolved.