Ronbo
I created a userform with a listbox (ListBox1) and a commandbutton
(OKButton). Here is the click event for the commandbutton
Private Sub OKButton_Click()
If Me.ListBox1.ListIndex -1 Then
Sheet1.Range("B44").End(xlUp).Offset(1, 0).Value _
= Me.ListBox1.Value
End If
End Sub
If nothing happened when with the last bit of code I gave you, then it's
likely that your commandbutton is not named OKButton. With the userform
open, double click on the commandbutton and the VBE with put the Sub and End
Sub lines in there for you. Something should have happened even if it was
wrong.
You can't use the AddItem method and the RowSource property. It's one or
the other. That's why you got errors from KIC's code.
Make sure your controls are named the same as mine (or change the code to
reflect your names) and this code should work.
Post back if it doesn't or if you have further questions.
--
Dick Kusleika
MVP - Excel
Excel Blog - Daily Dose of Excel
www.dicks-blog.com
"Ronbo" wrote in message
...
"Dick Kusleika" wrote:
Ronbo
P.S. Thanks to Dick Kusleika for the previous suggestions, but
neither
solved my problem.
Thanks a lot to Dick and keepITcool for your help. As you can see I
struggle with VBA but this one is ridiculous. I am still not getting
anywhere other than creating the UserForm named Food List with the ListBox
(ListBox1) and two CommandButtons (OKButton) and (CancelButton). The data
in the FoodList is created by using a named range in the ?oListBox ?"
RowSource?
With a Macro Button ?oAdd Item(s)? (code - FoodList.Show) on the
worksheet it
brings up the list and I can highlight the item(s) I want to add. With
the
Cancel Button (code - Unload FoodList) it closes the UserForm.
But I can?Tt get my OK button to transfer the selected items to the
worksheet
in column B.
With Dicks suggestion I put the code in the ?oPrivate Sub
OKButton_Click()?
and nothing happens. Also it looks like the code is finding the next open
cell going up column B. If so this will not work because B45 has text.
The
open cells to transfer data to, are B10..B44. As for the link, there are
two
errors in the code. One in the sTitle line and the other in the If line
and I
can?Tt see the error.
With keepITcool?Ts suggestion I develop the macro/routine
?oTransferToSheet?
and add the two Private sub?Ts ?oPrivate Sub UserForm_Click()? and
?oPrivate
Sub UserForm_Initialize()? and add two items with;
With ListBox1
.AddItem ?oOJ?
.AddItem ?oBeer?
End With
Now when I click on my ?oAdd Item(s)? button it stops with
?oPermission
denied?. Also I do not understand ?oInitialize()? at all, and seems
like I
would have to add items to the routine every time a wanted to add
something,
rather than just using the range in ?oRowSource.??
So I am still stuck. Any additional help will be truly appreciated.
Again thanks for you help, patience, and expertise.
P.S. Dick, I am sure you know how to make this work, I am the one that
can?Tt. As for using the thread, this is one of my first times on the
new
board and using the old board, if you posted a thread it never seemed to
get
read. Hopefully this will find its way to you and keepITcool.
Don't start a new thread, reply to my message and tell me WHY it doesn't
work. At the risk of being boastful, I'm quite sure that my answer was
adequate based on the information you provided.
--
Dick Kusleika
MVP - Excel
Excel Blog - Daily Dose of Excel
www.dicks-blog.com