PDA

View Full Version : [SOLVED:] Comndbutton code



ezluver
01-01-2005, 12:31 AM
Hi,

How would you assign a comndbutton to get value from selected item in combobox into a new cell each time you click on the comndbutton (add new item).? say I want to add the new item to column A in sheet 1. A1,A2...etc

code for that is really appreciated.

Thanks

Jacob Hilderbrand
01-01-2005, 01:07 AM
Try this code:



Private Sub CommandButton1_Click()
Sheets("Sheet1").Range("A65536").End(xlUp).Offset(1, 0).Value = _
Me.ComboBox1.Text
End Sub

Assuming that the Combo Box is named ComboBox1 and the Command Button is named CommandButton1.

ezluver
01-01-2005, 01:14 AM
That was fast & great response....... THX

Jacob Hilderbrand
01-01-2005, 01:15 AM
You're Welcome

Take Care

ezluver
01-02-2005, 03:42 AM
I promise last question (at least for now) :*)

How would make that code associated with another cell. say I want the user to select the item# first (1,2...) then when you click on add item button it will add it to: 1=A1, 2=A2 ...etc

Thanks,

Jacob Hilderbrand
01-02-2005, 04:09 AM
You can use a Select Case statement to check the value of the Combo Box.

Option Explicit

Private Sub CommandButton1_Click()

Select Case Me.ListBox1.Text
Case Is = "Text1"
Sheets("Sheet1").Range("A65536").End(xlUp).Offset(1, 0).Value = _
Me.ComboBox1.Text
Case Is = "Text2"
Sheets("Sheet1").Range("B65536").End(xlUp).Offset(1, 0).Value = _
Me.ComboBox1.Text
Case Is = "Text3"
Sheets("Sheet1").Range("C65536").End(xlUp).Offset(1, 0).Value = _
Me.ComboBox1.Text
Case Is = "Text4"
Sheets("Sheet1").Range("D65536").End(xlUp).Offset(1, 0).Value = _
Me.ComboBox1.Text
End Select

End Sub

ezluver
01-02-2005, 04:26 AM
You see this would be a very long code if I have a long item# list. can it just read the input value in the item# list then reflect it on the other sheet?