How to set value in the dropdown from a JSON data list?

Adding data to a user defined area using vba

  • QUESTION: I hope you can help me with this. On sheet one I have a button to show a userform. The user form has 5 textboxes and a command button. Sheet2 is used as storage for information, it is arranged into sections 4 cells across with a section heading in the top left cell. Data is stored below the heading in horizontal lines of four cells. The user will enter the heading of the section he wishes to add to in the first textbox on the form, then the data to be stored into the four other textboxes. The code should find the heading that the user entered and then find the next empty four cell line below it. It should then enter the data from the other textboxes into those cells. Im not sure if I have explained that well but I can send an example workbook that just explains what i need abit better. Here is the code that I am tring to use at the moment, it doesnt work...but I cant figure out what is wrong with it, it doesnt bring and compile errors, it just doesnt do anything. Private Sub AddNewOrder_Click() Dim r As Long, rFind As Range With Sheets("Bristol Order Storage") Set rFind = .Find(what:=AddNewOrderTextBox1.Value, Lookat:=xlWhole) If Not rFind Is Nothing Then r = rFind.End(xlDown).Row + 1 .Cells(r, 5).Value = Me.AddNewOrderTextBox2.Value .Cells(r, 6).Value = Me.AddNewOrderTextBox3.Value .Cells(r, 7).Value = Me.AddNewOrderTextBox4.Value .Cells(r, 8).Value = Me.AddNewOrderTextBox5.Value End If End With End Sub Anyhelp with figuring this out would be much appreciated. ANSWER: Not sure what you mean by "...doesnt bring and compile errors..." But regardless it looks like you need to use: Set rFind = .Find(what:=ME.AddNewOrderTextBox1.Value, Lookat:=xlWhole) If the code does nothing then that tells me that it did not find what it was trying to find. I'd suggest using a listbox or combobox to display all of the headings, IF I understand what you are describing, instead of forcing the user to type that. You run the risk of the user typing the wrong words. From there you can use the index property of the item selected in the dropdown to know where the data typed in the other textboxes should be placed. You will not have to use FIND at all. ---------- FOLLOW-UP ---------- QUESTION: I have tried editing the code to this: Private Sub AddNewOrder_Click() Dim r As Long, rFind As Range With Sheets("Bristol Order Storage") Set rFind = .Find(what:=Me.AddNewOrderTextBox1.Value, Lookat:=xlWhole) If Not rFind Is Nothing Then r = rFind.End(xlDown).Row + 1 .Cells(r, 5).Value = Me.AddNewOrderTextBox2.Value .Cells(r, 6).Value = Me.AddNewOrderTextBox3.Value .Cells(r, 7).Value = Me.AddNewOrderTextBox4.Value .Cells(r, 8).Value = Me.AddNewOrderTextBox5.Value End If End With If AddNewOrderTextBox1.Value = 0 Then MsgBox "Please enter the name of the Buyer for the order you wish to add" End If End Sub Now is get Runtime error 438 object doesnt support this property or method. A listbox i dont think would be good as it would be a very long list. I am definatley typing the correct heading name but for some reason it just doesnt find it in the storage sheet. Any ideas?

  • Answer:

    Since you did not WHERE in the code the error is occurring, that would have been helpful, then it is hard for me to say what is wrong. Regardless, try: Dim What_To_Find as String What_To_Find = Me.AddNewOrderTextBox1 Set rFind = .Find(what:=What_To_Find, Lookat:=xlWhole) And put a breakpoint in your code and the step thru your code - that can be helpful

Miningco.com Visit the source

Was this solution helpful to you?

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.