Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default List box value returns the row number of the list box range row

Hi, I was hoping someone could help me figure out what I am doing wrong.

I have a list box set up on a worksheet and I want the user to select a
value from the list box, and then have that value entered into a cell when a
button is clicked.

When I run/step through the macro, it takes a value and places it into the
appropriate cell. The problem is that the value which is placed in the cell
is not the value from the listbox, but the row number of the value that was
chosen. Using the below row numbers and values as an example; if I select
value 7 from the list box, the value that is returned is 2, not 7. If I
select 9A, the value returned is 4. The listbox value range is on different
worksheet than the worksheet where I want to place the listbox value. The
listbox range is currently one column with about 200 rows.

Worksheet Row Number Value
1 6
2 7
3 8
4 9A
5 10B

The condensed version of the code (excluding how I choose the cell) is:

Dim listvalue As String
Dim rowcounter As Integer
Dim EOBpointer As Range

Worksheets("Timer").Activate
ActiveSheet.Shapes("List Box 8").Select

rowcounter = 35

listvalue = Selection.Value

Set EOBpointer = Range("c" & rowcounter)
EOBpointer.Select
Selection.Value = listvalue
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default List box value returns the row number of the list box range row

There are two listboxes you can place on a worksheet.

The first is from the Forms toolbar. Its value is an index into its list.

The second is from the Control toolbox toolbar. Its value is the value you see
in the listbox.

If your listbox (either type) is a single selection, then you don't need to use
a macro to get the value.

If the listbox is from the forms toolbar:
rightclick on the listbox
Choose Format Control
Then on the Control tab, you can assign a cell link (say A1).

Then in B1 (the second cell), you can use that value/index in A1 to retrieve the
value from the list:

=if(a1=0,"",index(sheet2!a1:a11,a1)
where your list is on sheet2 in cells A1:A11


If your listbox is from the control toolbox toolbar, you can just go into design
mode (another icon on that toolbar) and then

rightclick on the listbox
Choose Properties
Scroll down to LinkedCell and type in the address of the cell you want to use.


If your listbox (either type) is multiselect, then this won't work and you will
need code.

=========
It sounds like you're using the listbox from the Forms toolbar.

If you have to use code (as part of a bigger routine), then you could use:

dim myLB8Val as string
with worksheets("timer")
with .listboxes("list box 8")
if .listindex = 0 then
mylb8val = "" 'not chosen
else
mylb8val = .list(.listindex)
end if
end with
end with

msgbox mylb8val

Tim at MBS wrote:

Hi, I was hoping someone could help me figure out what I am doing wrong.

I have a list box set up on a worksheet and I want the user to select a
value from the list box, and then have that value entered into a cell when a
button is clicked.

When I run/step through the macro, it takes a value and places it into the
appropriate cell. The problem is that the value which is placed in the cell
is not the value from the listbox, but the row number of the value that was
chosen. Using the below row numbers and values as an example; if I select
value 7 from the list box, the value that is returned is 2, not 7. If I
select 9A, the value returned is 4. The listbox value range is on different
worksheet than the worksheet where I want to place the listbox value. The
listbox range is currently one column with about 200 rows.

Worksheet Row Number Value
1 6
2 7
3 8
4 9A
5 10B

The condensed version of the code (excluding how I choose the cell) is:

Dim listvalue As String
Dim rowcounter As Integer
Dim EOBpointer As Range

Worksheets("Timer").Activate
ActiveSheet.Shapes("List Box 8").Select

rowcounter = 35

listvalue = Selection.Value

Set EOBpointer = Range("c" & rowcounter)
EOBpointer.Select
Selection.Value = listvalue


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default List box value returns the row number of the list box range ro

Thanks Dave,
I did use the form control list box. I'll try to see if I can use the code
you sent, but I don't need a msgbox with the value. I need to put the value
in the cell.

I would use the cell reference option, but the cell that the value needs to
go to will change everytime a value is chosen.

I was trying to write something quick that I could use for time studies to
capture a start and stop time. The list box is to select a code that
corresponds to the type of operation the person is doing. The data would be
organized like a record with code, start time and stop time on the same row,
but in separate columns. Each time the start button is pressed, the code
from the list box would be passed to the cell on the current row. The start
time would then be entered in the start time cell on that row. When the stop
button is pressed, it would populate the stop time, increment the row counter
and get ready for the next observation.

thanks,
Tim
"Dave Peterson" wrote:

There are two listboxes you can place on a worksheet.

The first is from the Forms toolbar. Its value is an index into its list.

The second is from the Control toolbox toolbar. Its value is the value you see
in the listbox.

If your listbox (either type) is a single selection, then you don't need to use
a macro to get the value.

If the listbox is from the forms toolbar:
rightclick on the listbox
Choose Format Control
Then on the Control tab, you can assign a cell link (say A1).

Then in B1 (the second cell), you can use that value/index in A1 to retrieve the
value from the list:

=if(a1=0,"",index(sheet2!a1:a11,a1)
where your list is on sheet2 in cells A1:A11


If your listbox is from the control toolbox toolbar, you can just go into design
mode (another icon on that toolbar) and then

rightclick on the listbox
Choose Properties
Scroll down to LinkedCell and type in the address of the cell you want to use.


If your listbox (either type) is multiselect, then this won't work and you will
need code.

=========
It sounds like you're using the listbox from the Forms toolbar.

If you have to use code (as part of a bigger routine), then you could use:

dim myLB8Val as string
with worksheets("timer")
with .listboxes("list box 8")
if .listindex = 0 then
mylb8val = "" 'not chosen
else
mylb8val = .list(.listindex)
end if
end with
end with

msgbox mylb8val

Tim at MBS wrote:

Hi, I was hoping someone could help me figure out what I am doing wrong.

I have a list box set up on a worksheet and I want the user to select a
value from the list box, and then have that value entered into a cell when a
button is clicked.

When I run/step through the macro, it takes a value and places it into the
appropriate cell. The problem is that the value which is placed in the cell
is not the value from the listbox, but the row number of the value that was
chosen. Using the below row numbers and values as an example; if I select
value 7 from the list box, the value that is returned is 2, not 7. If I
select 9A, the value returned is 4. The listbox value range is on different
worksheet than the worksheet where I want to place the listbox value. The
listbox range is currently one column with about 200 rows.

Worksheet Row Number Value
1 6
2 7
3 8
4 9A
5 10B

The condensed version of the code (excluding how I choose the cell) is:

Dim listvalue As String
Dim rowcounter As Integer
Dim EOBpointer As Range

Worksheets("Timer").Activate
ActiveSheet.Shapes("List Box 8").Select

rowcounter = 35

listvalue = Selection.Value

Set EOBpointer = Range("c" & rowcounter)
EOBpointer.Select
Selection.Value = listvalue


--

Dave Peterson
.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default List box value returns the row number of the list box range ro

I used the msgbox just to show that it was working ok.

msgbox mylb8val
could be
somecell.value = mylb8val
where somecell was decided elsewhere in your code.

Tim at MBS wrote:

Thanks Dave,
I did use the form control list box. I'll try to see if I can use the code
you sent, but I don't need a msgbox with the value. I need to put the value
in the cell.

I would use the cell reference option, but the cell that the value needs to
go to will change everytime a value is chosen.

I was trying to write something quick that I could use for time studies to
capture a start and stop time. The list box is to select a code that
corresponds to the type of operation the person is doing. The data would be
organized like a record with code, start time and stop time on the same row,
but in separate columns. Each time the start button is pressed, the code
from the list box would be passed to the cell on the current row. The start
time would then be entered in the start time cell on that row. When the stop
button is pressed, it would populate the stop time, increment the row counter
and get ready for the next observation.

thanks,
Tim
"Dave Peterson" wrote:

There are two listboxes you can place on a worksheet.

The first is from the Forms toolbar. Its value is an index into its list.

The second is from the Control toolbox toolbar. Its value is the value you see
in the listbox.

If your listbox (either type) is a single selection, then you don't need to use
a macro to get the value.

If the listbox is from the forms toolbar:
rightclick on the listbox
Choose Format Control
Then on the Control tab, you can assign a cell link (say A1).

Then in B1 (the second cell), you can use that value/index in A1 to retrieve the
value from the list:

=if(a1=0,"",index(sheet2!a1:a11,a1)
where your list is on sheet2 in cells A1:A11


If your listbox is from the control toolbox toolbar, you can just go into design
mode (another icon on that toolbar) and then

rightclick on the listbox
Choose Properties
Scroll down to LinkedCell and type in the address of the cell you want to use.


If your listbox (either type) is multiselect, then this won't work and you will
need code.

=========
It sounds like you're using the listbox from the Forms toolbar.

If you have to use code (as part of a bigger routine), then you could use:

dim myLB8Val as string
with worksheets("timer")
with .listboxes("list box 8")
if .listindex = 0 then
mylb8val = "" 'not chosen
else
mylb8val = .list(.listindex)
end if
end with
end with

msgbox mylb8val

Tim at MBS wrote:

Hi, I was hoping someone could help me figure out what I am doing wrong.

I have a list box set up on a worksheet and I want the user to select a
value from the list box, and then have that value entered into a cell when a
button is clicked.

When I run/step through the macro, it takes a value and places it into the
appropriate cell. The problem is that the value which is placed in the cell
is not the value from the listbox, but the row number of the value that was
chosen. Using the below row numbers and values as an example; if I select
value 7 from the list box, the value that is returned is 2, not 7. If I
select 9A, the value returned is 4. The listbox value range is on different
worksheet than the worksheet where I want to place the listbox value. The
listbox range is currently one column with about 200 rows.

Worksheet Row Number Value
1 6
2 7
3 8
4 9A
5 10B

The condensed version of the code (excluding how I choose the cell) is:

Dim listvalue As String
Dim rowcounter As Integer
Dim EOBpointer As Range

Worksheets("Timer").Activate
ActiveSheet.Shapes("List Box 8").Select

rowcounter = 35

listvalue = Selection.Value

Set EOBpointer = Range("c" & rowcounter)
EOBpointer.Select
Selection.Value = listvalue


--

Dave Peterson
.


--

Dave Peterson
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
looking up a value only if it returns a value in another list Richard New Users to Excel 11 March 15th 10 11:21 PM
Use VBA to reset data validation (=list) value to first value in that list (list is a named range) ker_01 Excel Programming 7 October 27th 08 03:13 PM
Is there a formula that returns the number at the bottom of a list mpenkala Excel Discussion (Misc queries) 4 February 4th 08 09:59 PM
User List Box - List from Hidden range - VBA worng Stan Excel Programming 4 October 19th 07 09:00 PM
Condensing a list/range with blank cells to a new list/range without blanks KR Excel Worksheet Functions 4 July 5th 05 04:23 PM


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

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

About Us

"It's about Microsoft Excel"