Listboxes

C

C Brehm

I am pulling my hair out on this one (what little is left).

Have a listbox LBclerk1
When I set the value by code

Worksheets("daily").LBClerk1.Value = .Range("s" & rc).Value

The listbox itself does not update with the new value. As near as I can tell
that is because the boundvalue does not update to.
I have tried to set the bound value and the listindex but to no avail.
If I choose another worksheet and then chose the worksheet with the listbox
it will now show the correct value. Doing so in code with
worksheets("x").select does not work. What am I missing? Or, is there a
site that explains using listboxes and how to code for this?

Thanks Carl
 
J

JLGWhiz

P.S. When you are not using code inside a With statement, do not use the
period in front of Range, [.Range]. It can confuse the compiler. You would
only use the .Range syntax if you are using something like With Worksheet(2).
Then the
[.] before the Range tells VBA that the Range belongs to Worksheet(2) and
not the ActiveSheet.
 
C

C Brehm

Thanks, but nothing there has helped. I looked through over 40 articles in
the knowledge base.
What really gets me is

Worksheets("daily").LBClerk1.Listindex

in the immediate widow works.
Does exactly what I want. But in code it returns an error.

PS.I only use .range is only used inside a with statement.
 
J

JLGWhiz

The three most common methods of returning a listbox value to a range in VBA
are:

myRange = ListBox1.Value (For single select lists)
myRange = ListBox1.ListIndex(i) (When BoundColumn is at 0)
myRange = ListBox1.Selected(i) (For Multiselection lists)

I have not seen any other methods used, but that does not mean they are not
out there.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top