Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Listbox in form

Hi,

Trying to get a listbox to work in a form... but not quite there yet!

The list should read the info from a range, but it empty... The code I
am using is below

Private Sub clients_select_Initialize()
Dim rng As Range, cel As Range
Set rng = ActiveWorkbook.Sheets("clients").Range("b2:b200")
With Me.clients_select_list
.Clear
For Each cel In rng.Cells
.AddItem cel.Value
Next
End With
End Sub

thanks a million
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 897
Default Listbox in form

I'm trying to test your code, but what is the name of the form and
what is the name if the listbox?

--JP

On Oct 6, 11:29*am, PA wrote:
Hi,

Trying to get a listbox to work in a form... but not quite there yet!

The list should read the info from a range, but it empty... The code I
am using is below

Private Sub clients_select_Initialize()
* * Dim rng As Range, cel As Range
* * Set rng = ActiveWorkbook.Sheets("clients").Range("b2:b200")
* * With Me.clients_select_list
* * * * .Clear
* * * * For Each cel In rng.Cells
* * * * * * .AddItem cel.Value
* * * * Next
* * End With
End Sub

thanks a million


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Listbox in form

Hi thanks for your (very) quick reply!!!

My form is "clients_select" and the list is "clients_select_list"

Thanks-

PA

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Listbox in form

Provided everything else is correct replace ".AddItem cel.Value" with
".AddItem(cel.Value)"

Regards,
The Code Cage Team
http://www.thecodecage.com/forumz/

"PA" wrote:

Hi,

Trying to get a listbox to work in a form... but not quite there yet!

The list should read the info from a range, but it empty... The code I
am using is below

Private Sub clients_select_Initialize()
Dim rng As Range, cel As Range
Set rng = ActiveWorkbook.Sheets("clients").Range("b2:b200")
With Me.clients_select_list
.Clear
For Each cel In rng.Cells
.AddItem cel.Value
Next
End With
End Sub

thanks a million

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Listbox in form

You should not try to type the procedure headers in long hand; rather, use
the dropdown box on the left side of the code window to pick the object and
use the dropdown box on the right side of the code window to pick the event
procedure. If you would have done that, you would have found that the proper
header for the UserForm's Initialize event was not this...

Private Sub clients_select_Initialize()

but, rather, that it was this instead...

Private Sub UserForm_Initialize()

Also, this part of the code (the header and footer) would not have required
you to type anything (especially useful for events having long headers such
as MouseDown).

--
Rick (MVP - Excel)


"PA" wrote in message
...
Hi,

Trying to get a listbox to work in a form... but not quite there yet!

The list should read the info from a range, but it empty... The code I
am using is below

Private Sub clients_select_Initialize()
Dim rng As Range, cel As Range
Set rng = ActiveWorkbook.Sheets("clients").Range("b2:b200")
With Me.clients_select_list
.Clear
For Each cel In rng.Cells
.AddItem cel.Value
Next
End With
End Sub

thanks a million




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Listbox in form

No, you should not use parentheses here nor anywhere else where they are not
required by syntax. While it would work here without problem, doing so can
get you in trouble in other situations (by either generating errors for
calls requiring multiple arguments or generating incorrect results in ByRef
arguments used to pass values from the called code back into the calling
code).

--
Rick (MVP - Excel)


"The Code Cage Team" wrote in
message ...
Provided everything else is correct replace ".AddItem cel.Value" with
".AddItem(cel.Value)"

Regards,
The Code Cage Team
http://www.thecodecage.com/forumz/

"PA" wrote:

Hi,

Trying to get a listbox to work in a form... but not quite there yet!

The list should read the info from a range, but it empty... The code I
am using is below

Private Sub clients_select_Initialize()
Dim rng As Range, cel As Range
Set rng = ActiveWorkbook.Sheets("clients").Range("b2:b200")
With Me.clients_select_list
.Clear
For Each cel In rng.Cells
.AddItem cel.Value
Next
End With
End Sub

thanks a million


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 897
Default Listbox in form

The correct code should be:

Private Sub UserForm_Initialize()
Dim rng As Range, cel As Range
Set rng = ActiveWorkbook.Sheets("clients").Range("b2:b200")
With Me.clients_select_list
.Clear
For Each cel In rng.Cells
.AddItem cel.Value
Next
End With
End Sub

You should review Rick's post -- never try to type out the names of
objects on your form, they are all available from the dropdowns at the
top of the code box.

--JP

On Oct 6, 11:49*am, PA wrote:
Hi thanks for your (very) quick reply!!!

My form is "clients_select" and the list is "clients_select_list"

Thanks-

PA


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Listbox in a form Dan Excel Programming 4 June 26th 07 04:21 PM
listbox value to a form alexanderd[_11_] Excel Programming 1 July 17th 05 04:24 PM
vb6 form with listbox RB Smissaert Excel Programming 2 June 2nd 05 11:23 PM
listbox option in form inquirer Excel Programming 2 April 7th 04 02:16 AM
Listbox/Form question Stuart[_5_] Excel Programming 1 August 24th 03 04:53 PM


All times are GMT +1. The time now is 01:48 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"