itemselected error

K

Kou Vang

I have several listboxes that are mult-selectable. In my code below, when I
select a row, I notice that the row I select in my listbox isn't being stated
in my code. So if I select index(1), it's not stating that I selected row 2?
I have all the listbox attributes the same, column 1, bound column 1,
multiselect=simple. I don't know what else to say?

Option Explicit:

Dim VarItm As Variant
Dim OrigVal, TotAvg
Dim I As Integer
Dim Per1, Per2, Per3

OrigVal = 0
I = 0
For Each VarItm In lstAdjHist2.ItemsSelected
OrigVal = OrigVal + Val(lstAdjHist2.Column(0, VarItm))
Debug.Print lstAdjHist2.Column(0, VarItm)
I = I + 1
Next VarItm

TotAvg = Round(OrigVal / I)
Debug.Print TotAvg
lstHistRec2.AddItem CStr(TotAvg)
 
D

Dale Fye

What happens if you define the variable type for OrigVal and TotAvg?

Dim OrigVal as Double, TotAvg as Double

What output are you getting from your debug statements? Try replacing the
first one with:

debug.print lstAdjHist2.Column(0, varItem), OrigVal


Dale
 
K

Kou Vang

I just noticed that when I select a row, the column no matter what for the
selected row is -1. So regardless of whatever index or row it was before, it
is now -1. Does that sound correct MVP guys? I will have to change my code
to account for this. Thanks.

Kou
 
D

Dale Fye

How are you implementing this code? Generally, it would be in the click
event of a command button or something like that. Can you post the entire
code segment from the declaration statement to the End Sub line?

Dale
--
Don''t forget to rate the post if it was helpful!

email address is invalid
Please reply to newsgroup only.
 

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