Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Adding selected items from one list box to two different list boxe


I created a userform, also have made three list boxes

List box 2 contains a default list of 10 companies I want selected, I want
the user to select two companies from here. Then the values (stored in
sheet.1 range) for the 1st company dropped into List box 3 and the other into
List box 4.

Currently, I am receiving a runtime error message '9' saying 'subscript out
of range'. please can someone help me sort this out. I pasted the relevant
part of the code below (I know am an amature VBA programmer). Thank you as I
await a response








Dim numofStock As Integer, daily As Integer, countSelected As Integer,
countSelectedi As Integer, countSelectedii As Integer
Dim column As Integer, row As Integer, i As Integer, j As Integer, k As
Integer, L As Integer
Dim SelectedStocki() As Variant, Stock() As Variant, SelectedStockii() As
Variant

numofStock = 10
daily = 1283
countSelectedi = 0
countSelectedii = 0

ReDim SelectedStocki(1 To daily, 1 To numofStock), Stock(1 To daily, 1 To
numofStock)
ReDim SelectedStockii(1 To daily, 1 To numofStock), Stock(1 To daily, 1 To
numofStock)

Stock = Sheet1.Range("Returns").Value

For column = 0 To numofStock - 1
If ListBox2.Selected(column) = True Then
countSelected = countSelectedi
countSelected = countSelectedii
Selection(countSelectedi) = ListBox2.List(column)
Selection(countSelectedii) = ListBox2.List(column)
For row = 1 To daily
SelectedStocki(row, countSelectedi) = Stock(row, column + 1)
Next row
For row = 1 To daily
SelectedStockii(row, countSelectedii) = Stock(row, column + 1)
Next row
End If
Next column
'Next column

ReDim Preserve SelectedStocki(1 To daily, 1 To countSelectedi)
ReDim Preserve SelectedStockii(1 To daily, 1 To countSelectedii)

With ListBox3
For j = 1 To countSelectedi
For i = 1 To daily
.AddItem Stock(i, j)
Next i
Next j
End With

With ListBox4
For k = 1 To countSelectedii
For L = 1 To daily
.AddItem Stock(k, L)
Next L
Next k
End With
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,533
Default Adding selected items from one list box to two different list boxe

Hi



Which line is highlighted when you click Debug?

Regards,
Per

"Genix" skrev i meddelelsen
...

I created a userform, also have made three list boxes

List box 2 contains a default list of 10 companies I want selected, I want
the user to select two companies from here. Then the values (stored in
sheet.1 range) for the 1st company dropped into List box 3 and the other
into
List box 4.

Currently, I am receiving a runtime error message '9' saying 'subscript
out
of range'. please can someone help me sort this out. I pasted the relevant
part of the code below (I know am an amature VBA programmer). Thank you as
I
await a response








Dim numofStock As Integer, daily As Integer, countSelected As Integer,
countSelectedi As Integer, countSelectedii As Integer
Dim column As Integer, row As Integer, i As Integer, j As Integer, k As
Integer, L As Integer
Dim SelectedStocki() As Variant, Stock() As Variant, SelectedStockii() As
Variant

numofStock = 10
daily = 1283
countSelectedi = 0
countSelectedii = 0

ReDim SelectedStocki(1 To daily, 1 To numofStock), Stock(1 To daily, 1 To
numofStock)
ReDim SelectedStockii(1 To daily, 1 To numofStock), Stock(1 To daily, 1 To
numofStock)

Stock = Sheet1.Range("Returns").Value

For column = 0 To numofStock - 1
If ListBox2.Selected(column) = True Then
countSelected = countSelectedi
countSelected = countSelectedii
Selection(countSelectedi) = ListBox2.List(column)
Selection(countSelectedii) = ListBox2.List(column)
For row = 1 To daily
SelectedStocki(row, countSelectedi) = Stock(row, column + 1)
Next row
For row = 1 To daily
SelectedStockii(row, countSelectedii) = Stock(row, column + 1)
Next row
End If
Next column
'Next column

ReDim Preserve SelectedStocki(1 To daily, 1 To countSelectedi)
ReDim Preserve SelectedStockii(1 To daily, 1 To countSelectedii)

With ListBox3
For j = 1 To countSelectedi
For i = 1 To daily
.AddItem Stock(i, j)
Next i
Next j
End With

With ListBox4
For k = 1 To countSelectedii
For L = 1 To daily
.AddItem Stock(k, L)
Next L
Next k
End With


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Adding selected items from one list box to two different list

Hi Per Jessen,
I hope you are still there. Thank you very much I have copied out the line
below. Please see what you can do. thank you

SelectedStocki(row, countSelectedi) = Stock(row, column + 1)

Genix


"Per Jessen" wrote:

Hi



Which line is highlighted when you click Debug?

Regards,
Per

"Genix" skrev i meddelelsen
...

I created a userform, also have made three list boxes

List box 2 contains a default list of 10 companies I want selected, I want
the user to select two companies from here. Then the values (stored in
sheet.1 range) for the 1st company dropped into List box 3 and the other
into
List box 4.

Currently, I am receiving a runtime error message '9' saying 'subscript
out
of range'. please can someone help me sort this out. I pasted the relevant
part of the code below (I know am an amature VBA programmer). Thank you as
I
await a response








Dim numofStock As Integer, daily As Integer, countSelected As Integer,
countSelectedi As Integer, countSelectedii As Integer
Dim column As Integer, row As Integer, i As Integer, j As Integer, k As
Integer, L As Integer
Dim SelectedStocki() As Variant, Stock() As Variant, SelectedStockii() As
Variant

numofStock = 10
daily = 1283
countSelectedi = 0
countSelectedii = 0

ReDim SelectedStocki(1 To daily, 1 To numofStock), Stock(1 To daily, 1 To
numofStock)
ReDim SelectedStockii(1 To daily, 1 To numofStock), Stock(1 To daily, 1 To
numofStock)

Stock = Sheet1.Range("Returns").Value

For column = 0 To numofStock - 1
If ListBox2.Selected(column) = True Then
countSelected = countSelectedi
countSelected = countSelectedii
Selection(countSelectedi) = ListBox2.List(column)
Selection(countSelectedii) = ListBox2.List(column)
For row = 1 To daily
SelectedStocki(row, countSelectedi) = Stock(row, column + 1)
Next row
For row = 1 To daily
SelectedStockii(row, countSelectedii) = Stock(row, column + 1)
Next row
End If
Next column
'Next column

ReDim Preserve SelectedStocki(1 To daily, 1 To countSelectedi)
ReDim Preserve SelectedStockii(1 To daily, 1 To countSelectedii)

With ListBox3
For j = 1 To countSelectedi
For i = 1 To daily
.AddItem Stock(i, j)
Next i
Next j
End With

With ListBox4
For k = 1 To countSelectedii
For L = 1 To daily
.AddItem Stock(k, L)
Next L
Next k
End With



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Adding selected items from one list box to two different list


Hi Per, please did I get lucky? Did you find anything yet?

Thanks


"Per Jessen" wrote:

Hi



Which line is highlighted when you click Debug?

Regards,
Per

"Genix" skrev i meddelelsen
...

I created a userform, also have made three list boxes

List box 2 contains a default list of 10 companies I want selected, I want
the user to select two companies from here. Then the values (stored in
sheet.1 range) for the 1st company dropped into List box 3 and the other
into
List box 4.

Currently, I am receiving a runtime error message '9' saying 'subscript
out
of range'. please can someone help me sort this out. I pasted the relevant
part of the code below (I know am an amature VBA programmer). Thank you as
I
await a response








Dim numofStock As Integer, daily As Integer, countSelected As Integer,
countSelectedi As Integer, countSelectedii As Integer
Dim column As Integer, row As Integer, i As Integer, j As Integer, k As
Integer, L As Integer
Dim SelectedStocki() As Variant, Stock() As Variant, SelectedStockii() As
Variant

numofStock = 10
daily = 1283
countSelectedi = 0
countSelectedii = 0

ReDim SelectedStocki(1 To daily, 1 To numofStock), Stock(1 To daily, 1 To
numofStock)
ReDim SelectedStockii(1 To daily, 1 To numofStock), Stock(1 To daily, 1 To
numofStock)

Stock = Sheet1.Range("Returns").Value

For column = 0 To numofStock - 1
If ListBox2.Selected(column) = True Then
countSelected = countSelectedi
countSelected = countSelectedii
Selection(countSelectedi) = ListBox2.List(column)
Selection(countSelectedii) = ListBox2.List(column)
For row = 1 To daily
SelectedStocki(row, countSelectedi) = Stock(row, column + 1)
Next row
For row = 1 To daily
SelectedStockii(row, countSelectedii) = Stock(row, column + 1)
Next row
End If
Next column
'Next column

ReDim Preserve SelectedStocki(1 To daily, 1 To countSelectedi)
ReDim Preserve SelectedStockii(1 To daily, 1 To countSelectedii)

With ListBox3
For j = 1 To countSelectedi
For i = 1 To daily
.AddItem Stock(i, j)
Next i
Next j
End With

With ListBox4
For k = 1 To countSelectedii
For L = 1 To daily
.AddItem Stock(k, L)
Next L
Next k
End With



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default Adding selected items from one list box to two different list

Hi Genix

Think I solved it.

The variable countSelectedi is equal to zero, and you have declared
SelectedStocki(from 1 to..) To verify that the variable value is zero
hold the mouse pointer over the variable when you click Debug.

Not sure what you are trying to do with theese lines:

countSelected = countSelectedi
countSelected = countSelectedii
Selection(countSelectedi) = ListBox2.List(column)
Selection(countSelectedii) = ListBox2.List(column)

First you set countSelected equal to countSelectedi then equal to
countSelectedii !?!

I just can't imagine what you want the two last lines to do.

Hopes this helps

---Per




On 13 Mar., 00:37, Genix wrote:
HiPer, please did I get lucky? Did you find anything yet?

Thanks



"PerJessen" wrote:
Hi


Which line is highlighted when you click Debug?


Regards,
Per


"Genix" skrev i meddelelsen
...


I created a userform, also have made three list boxes


List box 2 contains a default list of 10 companies I want selected, I want
the user to select two companies from here. Then the values (stored in
sheet.1 range) for the 1st company dropped into List box 3 and the other
into
List box 4.


Currently, I am receiving a runtime error message '9' saying 'subscript
out
of range'. please can someone help me sort this out. I pasted the relevant
part of the code below (I know am an amature VBA programmer). Thank you as
I
await a response


Dim numofStock As Integer, daily As Integer, countSelected As Integer,
countSelectedi As Integer, countSelectedii As Integer
Dim column As Integer, row As Integer, i As Integer, j As Integer, k As
Integer, L As Integer
Dim SelectedStocki() As Variant, Stock() As Variant, SelectedStockii() As
Variant


numofStock = 10
daily = 1283
countSelectedi = 0
countSelectedii = 0


ReDim SelectedStocki(1 To daily, 1 To numofStock), Stock(1 To daily, 1 To
numofStock)
ReDim SelectedStockii(1 To daily, 1 To numofStock), Stock(1 To daily, 1 To
numofStock)


Stock = Sheet1.Range("Returns").Value


For column = 0 To numofStock - 1
* *If ListBox2.Selected(column) = True Then
* * * *countSelected = countSelectedi
* * * *countSelected = countSelectedii
* * * *Selection(countSelectedi) = ListBox2.List(column)
* * * *Selection(countSelectedii) = ListBox2.List(column)
* * * *For row = 1 To daily
* * * * * *SelectedStocki(row, countSelectedi) = Stock(row, column + 1)
* * * *Next row
* * * *For row = 1 To daily
* * * * * *SelectedStockii(row, countSelectedii) = Stock(row, column + 1)
* * * *Next row
* *End If
Next column
'Next column


ReDim Preserve SelectedStocki(1 To daily, 1 To countSelectedi)
ReDim Preserve SelectedStockii(1 To daily, 1 To countSelectedii)


With ListBox3
* *For j = 1 To countSelectedi
* * * *For i = 1 To daily
* * * * * *.AddItem Stock(i, j)
* * * *Next i
* *Next j
End With


With ListBox4
* *For k = 1 To countSelectedii
* * * *For L = 1 To daily
* * * * * *.AddItem Stock(k, L)
* * * *Next L
* *Next k
End With- Skjul tekst i anførselstegn -


- Vis tekst i anførselstegn -




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Adding selected items from one list box to two different list

Hi Per,
Before I declare you my 'guru' please clarify, do I therefore declare it
equal to 1 rather? (for the error)

For the two lines, I am trying to tell VBA that when a user selects two
companies from the default companies list in List.box 2 column, VBA should
pick the first selection corresponding values for the range and place them
into a List.box 3.

Also, the second selection values should be placed in another List box named
4.

Actually, this is what I am trying to solve and not the error at such
because thats my objective to - take values for two companies in one list and
drop them individually into two separate list boxes. I think I am getting the
logic skewed

Please, any suggestions will be welcomed. Thank you, Per

Genix

"Per Jessen" wrote:

Hi Genix

Think I solved it.

The variable countSelectedi is equal to zero, and you have declared
SelectedStocki(from 1 to..) To verify that the variable value is zero
hold the mouse pointer over the variable when you click Debug.

Not sure what you are trying to do with theese lines:

countSelected = countSelectedi
countSelected = countSelectedii
Selection(countSelectedi) = ListBox2.List(column)
Selection(countSelectedii) = ListBox2.List(column)

First you set countSelected equal to countSelectedi then equal to
countSelectedii !?!

I just can't imagine what you want the two last lines to do.

Hopes this helps

---Per




On 13 Mar., 00:37, Genix wrote:
HiPer, please did I get lucky? Did you find anything yet?

Thanks



"PerJessen" wrote:
Hi


Which line is highlighted when you click Debug?


Regards,
Per


"Genix" skrev i meddelelsen
...


I created a userform, also have made three list boxes


List box 2 contains a default list of 10 companies I want selected, I want
the user to select two companies from here. Then the values (stored in
sheet.1 range) for the 1st company dropped into List box 3 and the other
into
List box 4.


Currently, I am receiving a runtime error message '9' saying 'subscript
out
of range'. please can someone help me sort this out. I pasted the relevant
part of the code below (I know am an amature VBA programmer). Thank you as
I
await a response


Dim numofStock As Integer, daily As Integer, countSelected As Integer,
countSelectedi As Integer, countSelectedii As Integer
Dim column As Integer, row As Integer, i As Integer, j As Integer, k As
Integer, L As Integer
Dim SelectedStocki() As Variant, Stock() As Variant, SelectedStockii() As
Variant


numofStock = 10
daily = 1283
countSelectedi = 0
countSelectedii = 0


ReDim SelectedStocki(1 To daily, 1 To numofStock), Stock(1 To daily, 1 To
numofStock)
ReDim SelectedStockii(1 To daily, 1 To numofStock), Stock(1 To daily, 1 To
numofStock)


Stock = Sheet1.Range("Returns").Value


For column = 0 To numofStock - 1
If ListBox2.Selected(column) = True Then
countSelected = countSelectedi
countSelected = countSelectedii
Selection(countSelectedi) = ListBox2.List(column)
Selection(countSelectedii) = ListBox2.List(column)
For row = 1 To daily
SelectedStocki(row, countSelectedi) = Stock(row, column + 1)
Next row
For row = 1 To daily
SelectedStockii(row, countSelectedii) = Stock(row, column + 1)
Next row
End If
Next column
'Next column


ReDim Preserve SelectedStocki(1 To daily, 1 To countSelectedi)
ReDim Preserve SelectedStockii(1 To daily, 1 To countSelectedii)


With ListBox3
For j = 1 To countSelectedi
For i = 1 To daily
.AddItem Stock(i, j)
Next i
Next j
End With


With ListBox4
For k = 1 To countSelectedii
For L = 1 To daily
.AddItem Stock(k, L)
Next L
Next k
End With- Skjul tekst i anførselstegn -


- Vis tekst i anførselstegn -



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default Adding selected items from one list box to two different list

Hi Genix

I'm still a bit confused...

but maybe the code below is what you need. If it doesn't help, you can
mail me a sample workbook with a description of what to do, and I'LL
give it a look.

Sub aaa()
Dim numofStock As Integer, daily As Integer, countSelected As Integer,
CountSelectedA As Integer, CountSelectedB As Integer
Dim column As Integer, row As Integer, i As Integer, j As Integer, k
As Integer, L As Integer
Dim SelectedStockA() As Variant, Stock() As Variant, SelectedStockB()
As Variant


numofStock = 10
daily = 1283
CountSelectedA = -1
CountSelectedB = -1

ReDim SelectedStockA(1 To daily, 1 To numofStock), Stock(1 To daily, 1
To numofStock)
ReDim SelectedStockB(1 To daily, 1 To numofStock), Stock(1 To daily, 1
To numofStock)

Stock = Sheet1.Range("Returns").Value

'Find two selected companies
For column = 0 To numofStock - 1
If me.listbox2.Selected(column) = True Then
If CountSelectedA = -1 Then
CountSelectedA = Me.listbox2.List(column)
Else
CountSelectedB = Me.listbox2.List(column)
End If
End If
Next
For column = 0 To numofStock - 1
For row = 1 To daily
SelectedStockA(row, CountSelectedA) = Stock(row, column + 1)
SelectedStockB(row, CountSelectedB) = Stock(row, column + 1)
Next row
Next

'Next column

' Why do you need to ReDim ?
ReDim Preserve SelectedStockA(1 To daily, 1 To CountSelectedA)
ReDim Preserve SelectedStockB(1 To daily, 1 To CountSelectedB)


With me.ListBox3
For j = 1 To CountSelectedA
For i = 1 To daily
.AddItem Stock(i, j)
Next i
Next j
End With


With me.ListBox4
For k = 1 To CountSelectedB
For L = 1 To daily
.AddItem Stock(k, L)
Next L
Next k
End With
End Sub

Hopes this helps
---

Per

On 13 Mar., 03:00, Genix wrote:
Hi Per,
Before I declare you my 'guru' please clarify, do I therefore declare it
equal to 1 rather? (for the error)

For the two lines, I am trying to tell VBA that when a user selects two
companies from the default companies list in List.box 2 column, VBA should
pick the first selection corresponding values for the range and place them
into a List.box 3.

Also, the second selection values should be placed in another List box named
4.

Actually, this is what I am trying to solve and not the error at such
because thats my objective to - take values for two companies in one list and
drop them individually into two separate list boxes. I think I am getting the
logic skewed

Please, any suggestions will be welcomed. Thank you, Per

Genix



"Per Jessen" wrote:
Hi Genix


Think I solved it.


The variable countSelectedi is equal to zero, and you have declared
SelectedStocki(from 1 to..) To verify that the variable value is zero
hold the mouse pointer over the variable when you click Debug.


Not sure what you are trying to do with theese lines:


countSelected = countSelectedi
countSelected = countSelectedii
Selection(countSelectedi) = ListBox2.List(column)
Selection(countSelectedii) = ListBox2.List(column)


First you set countSelected equal to countSelectedi then equal to
countSelectedii !?!


I just can't imagine what you want the two last lines to do.


Hopes this helps


---Per


On 13 Mar., 00:37, Genix wrote:
HiPer, please did I get lucky? Did you find anything yet?


Thanks


"PerJessen" wrote:
Hi


Which line is highlighted when you click Debug?


Regards,
Per


"Genix" skrev i meddelelsen
...


I created a userform, also have made three list boxes


List box 2 contains a default list of 10 companies I want selected, I want
the user to select two companies from here. Then the values (stored in
sheet.1 range) for the 1st company dropped into List box 3 and the other
into
List box 4.


Currently, I am receiving a runtime error message '9' saying 'subscript
out
of range'. please can someone help me sort this out. I pasted the relevant
part of the code below (I know am an amature VBA programmer). Thank you as
I
await a response


Dim numofStock As Integer, daily As Integer, countSelected As Integer,
countSelectedi As Integer, countSelectedii As Integer
Dim column As Integer, row As Integer, i As Integer, j As Integer, k As
Integer, L As Integer
Dim SelectedStocki() As Variant, Stock() As Variant, SelectedStockii() As
Variant


numofStock = 10
daily = 1283
countSelectedi = 0
countSelectedii = 0


ReDim SelectedStocki(1 To daily, 1 To numofStock), Stock(1 To daily, 1 To
numofStock)
ReDim SelectedStockii(1 To daily, 1 To numofStock), Stock(1 To daily, 1 To
numofStock)


Stock = Sheet1.Range("Returns").Value


For column = 0 To numofStock - 1
* *If ListBox2.Selected(column) = True Then
* * * *countSelected = countSelectedi
* * * *countSelected = countSelectedii
* * * *Selection(countSelectedi) = ListBox2.List(column)
* * * *Selection(countSelectedii) = ListBox2.List(column)
* * * *For row = 1 To daily
* * * * * *SelectedStocki(row, countSelectedi) = Stock(row, column + 1)
* * * *Next row
* * * *For row = 1 To daily
* * * * * *SelectedStockii(row, countSelectedii) = Stock(row, column + 1)
* * * *Next row
* *End If
Next column
'Next column


ReDim Preserve SelectedStocki(1 To daily, 1 To countSelectedi)
ReDim Preserve SelectedStockii(1 To daily, 1 To countSelectedii)


With ListBox3
* *For j = 1 To countSelectedi
* * * *For i = 1 To daily
* * * * * *.AddItem Stock(i, j)
* * * *Next i
* *Next j
End With


With ListBox4
* *For k = 1 To countSelectedii
* * * *For L = 1 To daily
* * * * * *.AddItem Stock(k, L)
* * * *Next L
* *Next k
End With- Skjul tekst i anførselstegn -


- Vis tekst i anførselstegn -- Skjul tekst i anførselstegn -


- Vis tekst i anførselstegn -


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
List and subtotal selected items, then print separate item list TitanG Excel Worksheet Functions 0 September 8th 08 09:07 PM
Filtering using multiple selected items in a list box snowiii Excel Programming 0 August 21st 08 07:38 PM
Feed Multiple Comb Boxe with same list ExcelMonkey Excel Programming 0 January 25th 08 09:29 PM
How do i find items selected in a list box ? Listbox use in Excel Excel Programming 7 June 30th 05 09:25 PM
named range, data validation: list non-selected items, and new added items KR Excel Discussion (Misc queries) 1 June 24th 05 05:21 AM


All times are GMT +1. The time now is 09:08 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"