Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default listing items from listbox

I have a listbox, the rowsource is a range on a worksheet.
When this listbox is brought up and names picked, I would like to have these
names entered starting on A4, going downward.
The names are always first and last name, maybe I can extract and copy, but
not sure how to do this.

Any ideas?

TIA
Gerry

Private Sub OKButton_Click()
msg = ""
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) Then msg = msg & ListBox1.List(i) & vbCrLf
Next i
MsgBox "You selected: " & msg & vbCrLf
Unload Me
With Worksheets("PrintJob").Range("A4")
.Value = msg
.WrapText = True
End With
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default listing items from listbox


I'm only new to programming in vba but I think I may have the answer to
your query.

You should use the 'offset' function. There is an excellent example
included in Martin Green's User Form Tutorial on exceltips.com
(http://www.exceltip.com/st/Create_Us...xcel/629.html).


The relevent part of the code is about halfway down the page relating
to the ok button that copies the data put into the form onto the
spreadsheet, much the same as what you are trying to do. The contexts
and explanations are all there so I strongly recommend you to follow
the link.

Happy vba-ing

Steve Flanagan
icemonkeysteve


--
icemonkeysteve
------------------------------------------------------------------------
icemonkeysteve's Profile: http://www.excelforum.com/member.php...fo&userid=1681
View this thread: http://www.excelforum.com/showthread...hreadid=152884

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default listing items from listbox


This function will return an array with the selected items.
(works for single and multiselect)

Optionally indicate which column to return. (1=second column)

If you have excel2000 or newer then THIS will produce a msgbox with the
selected items in listbox1:


Private Sub CommandButton1_Click()
MsgBox Join(GetSelected(Me.Controls("listbox1")), vbNewLine)
End Sub


Function GetSelected(mylst As MSForms.ListBox, _
Optional colNum As Integer)

Dim aRes As Variant
Dim i, n As Integer

With mylst
If .ListCount 0 Then
ReDim aRes(1 To .ListCount)
For i = 0 To .ListCount - 1
If .Selected(i) Then
n = n + 1
aRes(n) = .List(i, colNum)
End If
Next
End If
End With

If n 0 Then
ReDim Preserve aRes(1 To n)
GetSelected = aRes
End If
End Function



keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"Gerry" wrote:

I have a listbox, the rowsource is a range on a worksheet.
When this listbox is brought up and names picked, I would like to have
these names entered starting on A4, going downward.
The names are always first and last name, maybe I can extract and
copy, but not sure how to do this.

Any ideas?

TIA
Gerry

Private Sub OKButton_Click()
msg = ""
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) Then msg = msg & ListBox1.List(i) &
vbCrLf Next i
MsgBox "You selected: " & msg & vbCrLf
Unload Me
With Worksheets("PrintJob").Range("A4")
.Value = msg
.WrapText = True
End With
End Sub




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
how to drag items within listbox MP Excel Discussion (Misc queries) 0 January 15th 09 03:56 PM
listing unmatched items! via135 Excel Worksheet Functions 7 July 18th 06 06:53 PM
Listing all items only once guttyguppy Excel Discussion (Misc queries) 1 June 16th 06 03:07 PM
Counting items in a listbox Thurman Excel Programming 0 September 5th 03 06:36 AM
Checking Listbox Items Tim[_15_] Excel Programming 1 July 20th 03 05:27 PM


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