Avatar of Robert Casaletta
Robert Casaletta
Flag 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.
WAV_Activity_Recap.xlsm
Microsoft Office* Excel TableMicrosoft ExcelVBA

Avatar of undefined
Last Comment
Subodh Tiwari (Neeraj)

8/22/2022 - Mon
Subodh Tiwari (Neeraj)

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


Robert Casaletta

ASKER
I just tried the suggestion and still getting the run time 9 error....
Subodh Tiwari (Neeraj)

When do you get that error?
Can you let me know the action you perform which leads to that error?
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Robert Casaletta

ASKER
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)

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 Casaletta

ASKER
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.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Subodh Tiwari (Neeraj)

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 Casaletta

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

Also, thank you very much!!
ASKER CERTIFIED SOLUTION
Subodh Tiwari (Neeraj)

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Robert Casaletta

ASKER
K...again, appreciate the lesson...
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Robert Casaletta

ASKER
Quick response and easy solution.
Subodh Tiwari (Neeraj)

Glad your issue got resolved.