title: Generating Combobox and Editing Textbox on Userform using VBA
body: <p>Basically, I have a dialog box that I want to make</p>
  <p><a href="https://i.stack.imgur.com/WsSmL.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WsSmL.jpg" alt="enter image description here" /></a></p>
  <p>If you can see above, I want to make the combobox applied on Search by BDI Industry Group and CIF.</p>
  <p>Then, whenever I clicked the Search by Industry Group combobox and choose one, then the CIF field will give you another dropdown to choose, and then, the rest of other fields will be automatically filled based on the data below</p>
  <p><a href="https://i.stack.imgur.com/KOTtC.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KOTtC.jpg" alt="enter image description here" /></a></p>
  <p>The screenshot above is just a small part of my database. There are 7504 rows in total and the header starts from A2.</p>
  <p>Let's say I pick Transportation</p>
  <p>Then I want the dialog box shows me dropdown either CIF 13039099 and 12901262 to choose.</p>
  <p>Next, for example, when I picked CIF 13039099, the rest of other fields will show the information directly and automatically based on the database, which is:</p>
  <ul>
  <li>Client Name: Adit Jaya Mandiri' CV</li>
  <li>RM Name: Irawan Noor</li>
  <li>Segment: Commercial</li>
  </ul>
  <p>And I want <strong>Client Name</strong>, <strong>RM Name</strong>, and <strong>Segment</strong> are <strong>editable</strong>.</p>
  <p>After that when I click Save, It will be automatically updated based on the latest change. Is this possible to execute? Below is the VBA code which I made</p>
  <pre><code>Private Sub ComboBox1_Change()
  
  Me.ComboBox2 = &quot;&quot;
   
  Select Case Me.ComboBox1
  
      Case &quot;BDIIndustryGroup&quot;
  
          Me.ComboBox2.RowSource = &quot;BDIIndustryGroup&quot;
  
     
      Case &quot;CIF&quot;
  
          Me.ComboBox2.RowSource = &quot;CIF&quot;
  
  
      Case &quot;Client Name&quot;
  
          Me.ComboBox2.RowSource = &quot;CLientName&quot;
  
     
      Case &quot;RM Name&quot;
  
          Me.ComboBox2.RowSource = &quot;RM Name&quot;
     
  
      Case &quot;Segment&quot;
  
          Me.ComboBox2.RowSource = &quot;Segment&quot;
  
  End Select
  
  End Sub
  
  
  Private Sub UserForm_Initialize()
  
  Dim lastrow As Long
  
  Dim lastcolumn As Long
  
  lastcolumn = ActiveSheet.Cells(2, Columns.Count).End(xlToLeft).Column
  
  With Worksheets(&quot;sheet2&quot;)
  
  
      For I = 1 To lastcolumn
  
          With .Columns(I)
  
          lastrow = Sheet2.Cells(Rows.Count, I).End(xlUp).Row
  
              With Range(Cells(1, I), Cells(lastrow, I))
  
              Range(Cells(1, I), Cells(lastrow, I)).Select
  
              Selection.CreateNames Top:=True
  
              End With
  
          End With
  
      Next I
  
  End With
  
  
  Me.ComboBox1.RowSource = &quot;BDIIndustryGroup&quot;
        
  
  End Sub
  
   
  
  Private Sub CommandButton2_Click()
  
  Unload Me
  
  End Sub
  </code></pre>
  <p>I tried this code but it's not working as I wanted.</p>
  <p>I also got second alternative code from @Harun24HR but the CIF dropdown cannot be generated based on BDI Industry group.</p>
  <pre><code>'Codes to form
  
  Option Explicit
  
  Private matchRow As Long
  
  Private Sub Combobox1_Change()
  
  Dim rng As Range, cel As Range
  
  Dim lstrow As Long
  
  Dim strBDI As String
  
   
  
      strBDI = Me.ComboBox1
  
     
  
      lstrow = Cells(ActiveSheet.Rows.Count, &quot;E&quot;).End(xlUp).Row 'Change column E with BDI Industry Group column in case of you.
  
      Set rng = ActiveSheet.Range(&quot;E3:E&quot; &amp; lstrow)
  
     
  
      Me.ComboBox2.Clear
  
      For Each cel In rng
  
          If cel = strBDI Then
  
              Me.ComboBox2.AddItem cel.Offset(0, -4) '-4 need to adjust with CIF column left from BDI column
  
          End If
  
      Next
  
   
  
  End Sub
  
  Private Sub Combobox2_Change()
  
  Dim rng As Range, cel As Range
  
  Dim lstrow As Long
  
  Dim strBDI As String
  
  Dim strCIF As String
  
   
  
      strBDI = Me.ComboBox1
  
      strCIF = Me.ComboBox2
  
     
  
      lstrow = Cells(ActiveSheet.Rows.Count, &quot;E&quot;).End(xlUp).Row 'Change column E with BDI Group Industry column in case of you.
  
      Set rng = ActiveSheet.Range(&quot;E3:E&quot; &amp; lstrow)
  
     
  
      For Each cel In rng
  
          If cel = strBDI And cel.Offset(0, -4) = strCIF Then
  
              matchRow = cel.Row
  
              Exit For
  
          End If
  
      Next
  
     
  
      Me.TextBox1 = ActiveSheet.Cells(matchRow, 2)
  
      Me.TextBox2 = ActiveSheet.Cells(matchRow, 3)
  
      Me.TextBox3 = ActiveSheet.Cells(matchRow, 4)
  
     
  
  End Sub
  
  Private Sub cmdSave_Click()
  
      ActiveSheet.Cells(matchRow, 2) = Me.TextBox1
  
      ActiveSheet.Cells(matchRow, 3) = Me.TextBox2
  
      ActiveSheet.Cells(matchRow, 4) = Me.TextBox3
  
     
  
      MsgBox &quot;Data Saved Succesfully!&quot;, vbInformation, &quot;Save&quot;
  
     
  
  End Sub
  
  Private Sub UserForm_Initialize()
  
      'Add items manually or use sub to add unique items from BDI Industry Group column
  
      Me.ComboBox1.AddItem &quot;AUTOMOTIVE ATPM &amp; DEALER&quot;
  
      Me.ComboBox1.AddItem &quot;AUTOMOTIVE COMPONENT&quot;
  
      Me.ComboBox1.AddItem &quot;CABLE&quot;
  
      Me.ComboBox1.AddItem &quot;CEMENT&quot;
  
      Me.ComboBox1.AddItem &quot;CHEMICAL&quot;
  
      Me.ComboBox1.AddItem &quot;chemical &amp; PLASTICS&quot;
  
      Me.ComboBox1.AddItem &quot;COAL INDUSTRY&quot;
  
      Me.ComboBox1.AddItem &quot;COMPUTER &amp; RELATED&quot;
  
      Me.ComboBox1.AddItem &quot;CONSTRUCTION&quot;
  
      Me.ComboBox1.AddItem &quot;COSMETICS &amp; TOILETRIES&quot;
  
      Me.ComboBox1.AddItem &quot;CPO INDUSTRY&quot;
  
      Me.ComboBox1.AddItem &quot;ELECTRICITY &amp; POWER PLANT&quot;
  
      Me.ComboBox1.AddItem &quot;ENGINE MACHINERIES &amp; TOOLS&quot;
  
      Me.ComboBox1.AddItem &quot;FARMING &amp; ANIMAL FEED&quot;
  
      Me.ComboBox1.AddItem &quot;FINANCIAL SERVICES&quot;
  
      Me.ComboBox1.AddItem &quot;FISHERIES&quot;
  
      Me.ComboBox1.AddItem &quot;FOOD &amp; BEVERAGE&quot;
  
      Me.ComboBox1.AddItem &quot;FORESTRY &amp; WOOD PRODUCT&quot;
  
      Me.ComboBox1.AddItem &quot;FURNITURE&quot;
  
      Me.ComboBox1.AddItem &quot;GARMENT&quot;
  
      Me.ComboBox1.AddItem &quot;HOME APPLIANCES&quot;
  
      Me.ComboBox1.AddItem &quot;HOSPITAL &amp; HEALTHCARE&quot;
  
      Me.ComboBox1.AddItem &quot;HOTEL &amp; ACCOMMODATION SERVICE&quot;
  
      Me.ComboBox1.AddItem &quot;INFRASTRUCTURE&quot;
  
      Me.ComboBox1.AddItem &quot;MEDICAL EQUIPMENT&quot;
  
      Me.ComboBox1.AddItem &quot;METAL NON STEEL&quot;
  
      Me.ComboBox1.AddItem &quot;MINING &amp; QUARRING&quot;
  
      Me.ComboBox1.AddItem &quot;OIL &amp; GAS - DOWNSTREAM&quot;
  
      Me.ComboBox1.AddItem &quot;OIL &amp; GAS - UPSTREAM&quot;
  
      Me.ComboBox1.AddItem &quot;OTHERS&quot;
  
      Me.ComboBox1.AddItem &quot;PACKAGING &amp; CORRUGATED&quot;
  
      Me.ComboBox1.AddItem &quot;PETROCHEMICAL &amp; PLASTICS&quot;
  
      Me.ComboBox1.AddItem &quot;PHARMACEUTICAL&quot;
  
      Me.ComboBox1.AddItem &quot;PRINTING&quot;
  
      Me.ComboBox1.AddItem &quot;PROPERTIES &amp; REAL ESTATE&quot;
  
      Me.ComboBox1.AddItem &quot;PULP &amp; PAPER&quot;
  
      Me.ComboBox1.AddItem &quot;RENTAL SERVICES&quot;
  
      Me.ComboBox1.AddItem &quot;RETAILER&quot;
  
      Me.ComboBox1.AddItem &quot;RUBBER INDUSTRY&quot;
  
      Me.ComboBox1.AddItem &quot;SERVICE INDUSTRY&quot;
  
      Me.ComboBox1.AddItem &quot;SHIPPING&quot;
  
      Me.ComboBox1.AddItem &quot;STEEL&quot;
  
      Me.ComboBox1.AddItem &quot;SUGAR INDUSTRY&quot;
  
      Me.ComboBox1.AddItem &quot;TELECOMMUNICATION&quot;
  
      Me.ComboBox1.AddItem &quot;TEXTILE&quot;
  
      Me.ComboBox1.AddItem &quot;TOBACCO &amp; CIGARETTE&quot;
  
      Me.ComboBox1.AddItem &quot;TRANSPORTATION&quot;
  
      Me.ComboBox1.AddItem &quot;WHOLESALES TRADING&quot;
  
  End Sub
  </code></pre>
  <p>Any help would be greatly appreciated.</p>
  <p>Thank You.</p>