Excel VBA Combobox to query and insert

Easy excel user form and Combobox to query and insert data.

  • Insert user form using visual basic editor
  • Insert form controls: combobox, insert, query buttons, using floating toolbox|



The floating toolbox shows up as soon as you insert the form!

  • Double click each control to generate default handler
  • Copy and paste the below code for each handler
Private Sub ComboBox1_Change()

    With ThisWorkbook.Sheets("Sheet1")
    
        .Range("B1").value = ComboBox1.value
    
    End With

End Sub

Private Sub InsertButton_Click()
    
    With ThisWorkbook.Sheets("Sheet1")
    
        .Range("B1").value = ComboBox1.value
    
    End With
    
End Sub

Private Sub QueryButton_Click()

    With ThisWorkbook.Sheets("Sheet1")
    
        For Each cell In .Range("A1:A14")
        
            If cell.value = ComboBox1.value Then
            
                cell.Interior.Color = vbYellow
            
            End If
        
        Next cell
    
    End With

End Sub

Play around with the code inside the handlers to have the solution meet your needs.

0
VBA Choice MessageBox

No Comments

No comments yet

Leave a Reply

Your email address will not be published. Required fields are marked *