I think I may have answered the first question "off-line":
the listbox is an array.
array indexes start at 0
so, if your list is: line1, line2,line3 it looks like:
list(0) = line1
list(1) = line2
list(2) = line3

the total number of elements in the array (or listbox) is 3,
but the index is 0 to 2.

So, to loop through, you start at 0 and end at count - 1.

Now, assuming the item selected represents a row in your worksheet,
and your worksheet INCLUDES a header row:  
row1 = header
row2 = line1
row3 = line2
row4 = line3

let's say you've selected item 2,  representing the second row of data (on row 
#3)
In the first loop, it starts at i = 0 (value "line1")
the second loop, i = 1 (value "line2") is what you've selected.
So, you want to select the cell in column A, line THREE (second line of data 
after header)
so you use the loop counter i + 2
or: Range("A" & i + 2)

note:  If you can only select one item in your listbox (multiselect =false)
then you should add:

Exit For
after the Worksheets line.
otherwise, if you have 50 items in your listbox and select item 2, it still has 
to 

check the other 48 items.
once you found the selected item, you should exit the loop.
Unless you CAN select multiple items.

Paul


>
>From: neil johnson <neil.jh...@googlemail.com>
>To: talk2mar...@gmail.com; villager.g...@gmail.com
>Cc: excel-macros@googlegroups.com
>Sent: Thu, September 30, 2010 11:49:43 AM
>Subject: $$Excel-Macros$$ Please tell me what is meaning of this code
>
>Hi Sir,
>
>I am sending attached excel sheet in which user form display the dynamic 
>range. 
>When we select range in user form with the help of list box data goes to 
>another 
>sheet. Sir My question is the highlighted.: Why we do listcount -1 and other 
>question is that highlight cell .Sir I need your help. Because i am making 
>project . That is my first project . 
>
>
>
> Dim i As Long, j As Long
>   For i = 0 To Me.ListBox1.ListCount - 1( Why We do listcount -1)
>        If Me.ListBox1.Selected(i) Then
>           
>           Worksheets("Sheet1").Range("A" & i + 2).Resize(1, 6).Copy 
>Worksheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1)
>        End If
>    Next i
>-- 
>----------------------------------------------------------------------------------
>
>Some important links for excel users:
>1. Follow us on TWITTER for tips tricks and links : 
>http://twitter.com/exceldailytip
>2. Join our LinkedIN group @ http://www.linkedin.com/groups?gid=1871310
>3. Excel tutorials at http://www.excel-macros.blogspot.com
>4. Learn VBA Macros at http://www.quickvba.blogspot.com
>5. Excel Tips and Tricks at http://exceldailytip.blogspot.com
>
>To post to this group, send email to excel-macros@googlegroups.com
> 
><><><><><><><><><><><><><><><><><><><><><><>
>Like our page on facebook , Just follow below link
>http://www.facebook.com/pages/discussexcelcom/160307843985936?v=wall&ref=ts
>

-- 
----------------------------------------------------------------------------------
Some important links for excel users:
1. Follow us on TWITTER for tips tricks and links : 
http://twitter.com/exceldailytip
2. Join our LinkedIN group @ http://www.linkedin.com/groups?gid=1871310
3. Excel tutorials at http://www.excel-macros.blogspot.com
4. Learn VBA Macros at http://www.quickvba.blogspot.com
5. Excel Tips and Tricks at http://exceldailytip.blogspot.com
 
To post to this group, send email to excel-macros@googlegroups.com

<><><><><><><><><><><><><><><><><><><><><><>
Like our page on facebook , Just follow below link
http://www.facebook.com/pages/discussexcelcom/160307843985936?v=wall&ref=ts

Reply via email to