ComboBox If then Statement for moving cell

clarkp81

New Member
Joined
May 3, 2019
Messages
13
I am trying to have a spreadsheet enter the value of the NameTextBox into a cell if a selection in XYZComboBox is selected. However, when the code is run nothing happens. There are no errors indicated but still nothing appears in the selected box. The box that I would like the value to appear in moves down one row every time new data is entered which is why it is located using the find function. Any help would be greatly appreciated.

Private Sub OKButton_Click()

If Me.XYZComboBox.Value = "ABC" Then
Range(Cells.Find(what:="ABC").Address).Activate
Range(ActiveCell.Offset(0, 1)).Value = NameTextBox.Value
End If
end sub
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Try this

Code:
Private Sub OKButton_Click()


    If NameTextBox.Value = "" Then
        MsgBox "Enter data in NameTextBox"
        NameTextBox.SetFocus
        Exit Sub
    End If
    If Me.XYZComboBox.Value = "ABC" Then
        Set b = Cells.Find("ABC", LookIn:=xlValues, lookat:=xlWhole)
        If Not b Is Nothing Then
            b.Offset(0, 1).Value = NameTextBox.Value
        Else
            MsgBox "ABC, does no exists"
        End If
    Else
        MsgBox "Enter 'ABC' in combobox"
    End If
End Sub
 
Upvote 0
Thanks for the help. It didn't work, but I learned how to do msgbox. The code does pop up with the msg box, but doesn't enter the value of the name text box into the cell next to the ABC cell.
 
Upvote 0
Haha, very funny, well you always learn something.

You can put the code you are using, exactly what data you have in the combo, in the texbox and in the cell.
 
Upvote 0
I think that might be the easiest way. I really do appreciate the help though. Sorry if I came off as sarcastic.
 
Upvote 0
The success of a good code are the validations, maybe I exceeded in msgbox, but it is a way to reach a success.
The code works as you put your example:
Combo = "ABC"
some cell = "ABC"
Textbox = with some data
 
Upvote 0
The success of a good code are the validations, maybe I exceeded in msgbox, but it is a way to reach a success.
The code works as you put your example:
Combo = "ABC"
some cell = "ABC"
Textbox = with some data

Just wanted to let you know that your code did work after all. Thank you very much, I am sorry for doubting you.
 
Upvote 0
Follow up question. The cell that I am trying to enter the nametextbox.value into should contain more than one value. So when the next line of data is entered it would look some thing like "Simpson, Bart - Burns, Montgomery - etc"
I tried to use the code
b.Offset(0, 1).Value = NameTextBox.Value &""& NameTextBox.Value
but the only thing that happens is it deletes the original value and then adds the same name for every line of data. ie
Simpson,Bart
Burns,MontgomeryBurns,Montgomery
Smpson,LisaSimpson,LisaSimpson,Lisa
 
Upvote 0
It would also be okay if the next name just moved to an adjacent cell but b.Offset(0, 1)+1 didn't work.
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,269
Members
452,628
Latest member
dd2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top