Consulting

Results 1 to 3 of 3

Thread: Save textbox to specific cell based on combobox seletection

  1. #1
    VBAX Regular
    Joined
    Feb 2018
    Posts
    15
    Location

    Save textbox to specific cell based on combobox seletection

    Hi

    I am trying to save the text input in a textbox based on the combobox selection. for example

    A combobox with the options of :
    (Sheet3 Cell A1) Colour
    (Sheet3 Cell B1) Animal
    (Sheet3 Cell C1) Car
    (Sheet3 Cell D1) Country.

    A textbox where the user can input a text.
    A Button that saves the textbox text to a dynamic name range.

    I want the text in the textbox to be saved under the dynamic name range based on the selection of the combobox.

    for examlpe, if i have chosen Colour and wrote blue in the textbox, i want it to save the text (blue) on the next available empty cell in Sheet3 Cell B2.

    thanks in advance

  2. #2
    VBAX Expert
    Joined
    Sep 2016
    Posts
    788
    Location
    Option Explicit
    
    
    Private Sub CommandButton1_Click()
        Dim col As Long
        
        Select Case ComboBox1.Value
            Case "Colour":      col = 1
            Case "Animal":      col = 2
            Case "Car":         col = 3
            Case "Country":     col = 4
        End Select
        
        If col > 0 Then
            Sheets("Sheet3").Cells(Rows.Count, col).End(xlUp).Offset(1).Value = TextBox1.Value
        End If
        
    End Sub

  3. #3
    VBAX Regular
    Joined
    Feb 2018
    Posts
    15
    Location
    Thanks Mana

    I managed to get my code to work but your simplified it. here is what i was using.

    PHP Code:
    Private Sub cmdAdd_Click()
    Dim i As Long
    If Me.Combobox1.Text "Colour" Then    
    Sheet3
    .Activate    
    ActiveSheet
    .Range("A2").Activate    
    Do While IsEmpty(ActiveCell.Offset(i0)) = False      
    1    
    Loop    
    ActiveCell
    .Offset(i0).Value Textbox1.Value
    End 
    If

    If 
    Me.Combobox1.Text "Animal" Then    
    Sheet1
    .Activate    
    ActiveSheet
    .Range("B2").Activate   
     
    Do While IsEmpty(ActiveCell.Offset(i0)) = False      
    1    
    Loop    
    ActiveCell
    .Offset(i0).Value Textbox1.Value
    End 
    If

    'And repeat for rest

    End Sub 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •