Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Dynamically assign items to a list box

Hi,

Is there a way to automatically add items to a list box and then
programatically act according to the item selected by the user ?
This is the scenario:
I have a spreadsheet that keeps statistics of basketball games. Each time
the assistant to the coach needs to add the stats of a new game, he/she
clicks on a button (which is linked to a macro) and a new blank template is
appended to the end of the sheet. Then he/she fills the recently added
template and some calculations are done. Before exiting, the spreadsheet is
saved. I've been able to implement this by means of a couple of macros and a
bit of user-interface design. So far, so good.
The problem is that as long as the spreadsheet grows, it is more and more
time-consuming to locate the stats of any given game, requiring many
page-up's and page-down's and/or Edit | Search, so I thought that a feature
to automatically "jump" to the stats of the game of choice may come handy.
For this task, I thought of adding a list box (which should be linked to a
macro) whose items must be picked from -for example- the first cell of the
first row of every game, and then, according to the item or "game" selected
by the user, jump to that stat. That simple.
I thought of creating an autoexecutable macro that could -for example- run
when the .XLS file is opened and create the list box on the fly, however,
although I can programatically parse the whole sheet and read the content of
the cells that identify each game, I don't know how to feed the content of
these cells to the list box. I have no doubts it has to be possible to
implement this.

I'll highly appreciate if someone points me in the right direction to
achieve my goal.
Thank you,

Fernando Ronci
E-mail:


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Dynamically assign items to a list box

for rw = 1 to 2000 step 9

With Worksheets("Stats")
if isempty(.cells(rw,1)) then exit for
me.listbox1.AddItem .Cells(rw,1).Value & " " & .cells(rw,2).Value
End With

Next

--
Regards,
Tom Ogivly


"Fernando Ronci" wrote in message
...
Hi,

Is there a way to automatically add items to a list box and then
programatically act according to the item selected by the user ?
This is the scenario:
I have a spreadsheet that keeps statistics of basketball games. Each time
the assistant to the coach needs to add the stats of a new game, he/she
clicks on a button (which is linked to a macro) and a new blank template

is
appended to the end of the sheet. Then he/she fills the recently added
template and some calculations are done. Before exiting, the spreadsheet

is
saved. I've been able to implement this by means of a couple of macros and

a
bit of user-interface design. So far, so good.
The problem is that as long as the spreadsheet grows, it is more and more
time-consuming to locate the stats of any given game, requiring many
page-up's and page-down's and/or Edit | Search, so I thought that a

feature
to automatically "jump" to the stats of the game of choice may come handy.
For this task, I thought of adding a list box (which should be linked to a
macro) whose items must be picked from -for example- the first cell of the
first row of every game, and then, according to the item or "game"

selected
by the user, jump to that stat. That simple.
I thought of creating an autoexecutable macro that could -for example-

run
when the .XLS file is opened and create the list box on the fly, however,
although I can programatically parse the whole sheet and read the content

of
the cells that identify each game, I don't know how to feed the content of
these cells to the list box. I have no doubts it has to be possible to
implement this.

I'll highly appreciate if someone points me in the right direction to
achieve my goal.
Thank you,

Fernando Ronci
E-mail:




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Dynamically assign items to a list box

Thanks Tom, but I'm getting a compilation error with this:
me.listbox1.AddItem .Cells(rw,1).Value & " " & .cells(rw,2).Value
^^__ Use of keyword "Me" is not valid.

Do you know what can have gone wrong?
Thank you,
Fernando


"Tom Ogilvy" wrote in message
...
for rw = 1 to 2000 step 9

With Worksheets("Stats")
if isempty(.cells(rw,1)) then exit for
me.listbox1.AddItem .Cells(rw,1).Value & " " & .cells(rw,2).Value
End With

Next

--
Regards,
Tom Ogivly


"Fernando Ronci" wrote in message
...
Hi,

Is there a way to automatically add items to a list box and then
programatically act according to the item selected by the user ?
This is the scenario:
I have a spreadsheet that keeps statistics of basketball games. Each

time
the assistant to the coach needs to add the stats of a new game, he/she
clicks on a button (which is linked to a macro) and a new blank template

is
appended to the end of the sheet. Then he/she fills the recently added
template and some calculations are done. Before exiting, the spreadsheet

is
saved. I've been able to implement this by means of a couple of macros

and
a
bit of user-interface design. So far, so good.
The problem is that as long as the spreadsheet grows, it is more and

more
time-consuming to locate the stats of any given game, requiring many
page-up's and page-down's and/or Edit | Search, so I thought that a

feature
to automatically "jump" to the stats of the game of choice may come

handy.
For this task, I thought of adding a list box (which should be linked to

a
macro) whose items must be picked from -for example- the first cell of

the
first row of every game, and then, according to the item or "game"

selected
by the user, jump to that stat. That simple.
I thought of creating an autoexecutable macro that could -for example-

run
when the .XLS file is opened and create the list box on the fly,

however,
although I can programatically parse the whole sheet and read the

content
of
the cells that identify each game, I don't know how to feed the content

of
these cells to the list box. I have no doubts it has to be possible to
implement this.

I'll highly appreciate if someone points me in the right direction to
achieve my goal.
Thank you,

Fernando Ronci
E-mail:






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Dynamically assign items to a list box

Fernando,

If your code is in the userform's code module, the Me keyword
should work fine. If the code is elsewhere, change 'Me' to the
name of the userform.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Fernando Ronci" wrote in message
...
Thanks Tom, but I'm getting a compilation error with this:
me.listbox1.AddItem .Cells(rw,1).Value & " " &

..cells(rw,2).Value
^^__ Use of keyword "Me" is not valid.

Do you know what can have gone wrong?
Thank you,
Fernando


"Tom Ogilvy" wrote in message
...
for rw = 1 to 2000 step 9

With Worksheets("Stats")
if isempty(.cells(rw,1)) then exit for
me.listbox1.AddItem .Cells(rw,1).Value & " " &

..cells(rw,2).Value
End With

Next

--
Regards,
Tom Ogivly


"Fernando Ronci" wrote in message
...
Hi,

Is there a way to automatically add items to a list box and

then
programatically act according to the item selected by the

user ?
This is the scenario:
I have a spreadsheet that keeps statistics of basketball

games. Each
time
the assistant to the coach needs to add the stats of a new

game, he/she
clicks on a button (which is linked to a macro) and a new

blank template
is
appended to the end of the sheet. Then he/she fills the

recently added
template and some calculations are done. Before exiting,

the spreadsheet
is
saved. I've been able to implement this by means of a

couple of macros
and
a
bit of user-interface design. So far, so good.
The problem is that as long as the spreadsheet grows, it is

more and
more
time-consuming to locate the stats of any given game,

requiring many
page-up's and page-down's and/or Edit | Search, so I

thought that a
feature
to automatically "jump" to the stats of the game of choice

may come
handy.
For this task, I thought of adding a list box (which should

be linked to
a
macro) whose items must be picked from -for example- the

first cell of
the
first row of every game, and then, according to the item or

"game"
selected
by the user, jump to that stat. That simple.
I thought of creating an autoexecutable macro that

could -for example-
run
when the .XLS file is opened and create the list box on the

fly,
however,
although I can programatically parse the whole sheet and

read the
content
of
the cells that identify each game, I don't know how to feed

the content
of
these cells to the list box. I have no doubts it has to be

possible to
implement this.

I'll highly appreciate if someone points me in the right

direction to
achieve my goal.
Thank you,

Fernando Ronci
E-mail:








  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Dynamically assign items to a list box

Chip,

My code is outside of the userform's code module.
How do I find out (or set) the name of the "listbox" which I want to refer
from the code ?
Sorry, but I'll start learning OOP these days.

Thank you,
Fernando

"Chip Pearson" wrote in message
...
Fernando,

If your code is in the userform's code module, the Me keyword
should work fine. If the code is elsewhere, change 'Me' to the
name of the userform.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Fernando Ronci" wrote in message
...
Thanks Tom, but I'm getting a compilation error with this:
me.listbox1.AddItem .Cells(rw,1).Value & " " &

.cells(rw,2).Value
^^__ Use of keyword "Me" is not valid.

Do you know what can have gone wrong?
Thank you,
Fernando


"Tom Ogilvy" wrote in message
...
for rw = 1 to 2000 step 9

With Worksheets("Stats")
if isempty(.cells(rw,1)) then exit for
me.listbox1.AddItem .Cells(rw,1).Value & " " &

.cells(rw,2).Value
End With

Next

--
Regards,
Tom Ogivly


"Fernando Ronci" wrote in message
...
Hi,

Is there a way to automatically add items to a list box and

then
programatically act according to the item selected by the

user ?
This is the scenario:
I have a spreadsheet that keeps statistics of basketball

games. Each
time
the assistant to the coach needs to add the stats of a new

game, he/she
clicks on a button (which is linked to a macro) and a new

blank template
is
appended to the end of the sheet. Then he/she fills the

recently added
template and some calculations are done. Before exiting,

the spreadsheet
is
saved. I've been able to implement this by means of a

couple of macros
and
a
bit of user-interface design. So far, so good.
The problem is that as long as the spreadsheet grows, it is

more and
more
time-consuming to locate the stats of any given game,

requiring many
page-up's and page-down's and/or Edit | Search, so I

thought that a
feature
to automatically "jump" to the stats of the game of choice

may come
handy.
For this task, I thought of adding a list box (which should

be linked to
a
macro) whose items must be picked from -for example- the

first cell of
the
first row of every game, and then, according to the item or

"game"
selected
by the user, jump to that stat. That simple.
I thought of creating an autoexecutable macro that

could -for example-
run
when the .XLS file is opened and create the list box on the

fly,
however,
although I can programatically parse the whole sheet and

read the
content
of
the cells that identify each game, I don't know how to feed

the content
of
these cells to the list box. I have no doubts it has to be

possible to
implement this.

I'll highly appreciate if someone points me in the right

direction to
achieve my goal.
Thank you,

Fernando Ronci
E-mail:












  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Dynamically assign items to a list box

Fernando,

With the UserForm open in VBA, select the listbox in question,
press F4 to display the Properties window, and look at the Name
property.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Fernando Ronci" wrote in message
...
Chip,

My code is outside of the userform's code module.
How do I find out (or set) the name of the "listbox" which I

want to refer
from the code ?
Sorry, but I'll start learning OOP these days.

Thank you,
Fernando

"Chip Pearson" wrote in message
...
Fernando,

If your code is in the userform's code module, the Me keyword
should work fine. If the code is elsewhere, change 'Me' to

the
name of the userform.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Fernando Ronci" wrote in message
...
Thanks Tom, but I'm getting a compilation error with this:
me.listbox1.AddItem .Cells(rw,1).Value & " " &

.cells(rw,2).Value
^^__ Use of keyword "Me" is not valid.

Do you know what can have gone wrong?
Thank you,
Fernando


"Tom Ogilvy" wrote in message
...
for rw = 1 to 2000 step 9

With Worksheets("Stats")
if isempty(.cells(rw,1)) then exit for
me.listbox1.AddItem .Cells(rw,1).Value & " " &

.cells(rw,2).Value
End With

Next

--
Regards,
Tom Ogivly


"Fernando Ronci" wrote in

message
...
Hi,

Is there a way to automatically add items to a list box

and
then
programatically act according to the item selected by

the
user ?
This is the scenario:
I have a spreadsheet that keeps statistics of

basketball
games. Each
time
the assistant to the coach needs to add the stats of a

new
game, he/she
clicks on a button (which is linked to a macro) and a

new
blank template
is
appended to the end of the sheet. Then he/she fills the

recently added
template and some calculations are done. Before

exiting,
the spreadsheet
is
saved. I've been able to implement this by means of a

couple of macros
and
a
bit of user-interface design. So far, so good.
The problem is that as long as the spreadsheet grows,

it is
more and
more
time-consuming to locate the stats of any given game,

requiring many
page-up's and page-down's and/or Edit | Search, so I

thought that a
feature
to automatically "jump" to the stats of the game of

choice
may come
handy.
For this task, I thought of adding a list box (which

should
be linked to
a
macro) whose items must be picked from -for example-

the
first cell of
the
first row of every game, and then, according to the

item or
"game"
selected
by the user, jump to that stat. That simple.
I thought of creating an autoexecutable macro that

could -for example-
run
when the .XLS file is opened and create the list box on

the
fly,
however,
although I can programatically parse the whole sheet

and
read the
content
of
the cells that identify each game, I don't know how to

feed
the content
of
these cells to the list box. I have no doubts it has to

be
possible to
implement this.

I'll highly appreciate if someone points me in the

right
direction to
achieve my goal.
Thank you,

Fernando Ronci
E-mail:












  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Dynamically assign items to a list box

Thank you Chip,
I'm getting closer.
I was able to run this simple test macro:
Private Sub ListBox1_Click()

For rw = 1 To 5
With Worksheets("Hoja1")
Me.ListBox1.AddItem.Cells(rw, 1).Value
End With
Next

End Sub

However, when I run the macro (F5) the listbox is empty, I mean, the test
data at A1..E1 aren't shown within the listbox.
What am I missing ?
Thank you,
Fernando

"Chip Pearson" wrote in message
...
Fernando,

With the UserForm open in VBA, select the listbox in question,
press F4 to display the Properties window, and look at the Name
property.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




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
Assign a formula to count items in a column if they are within cor Josie Excel Worksheet Functions 1 October 16th 09 01:14 AM
dynamically sorted list with duplicates [email protected] Excel Worksheet Functions 5 April 29th 08 09:26 PM
Dynamically changing the size of a list [email protected] Excel Discussion (Misc queries) 2 July 1st 06 04:56 AM
named range, data validation: list non-selected items, and new added items KR Excel Discussion (Misc queries) 1 June 24th 05 05:21 AM
Assign macros to dynamically created form elements Joepy Excel Programming 4 March 3rd 04 09:03 PM


All times are GMT +1. The time now is 08:46 PM.

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"