Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Listbox Output to Individual Listboxes

I'm struggling to design a simple report in Word with visible CommandButtons
that will allow the user to open a UserForm, select appropriate data from
ListBoxes, and upon exiting the UserForm, populate individual ListBoxes on
the Word report. The respective UserForm1 consists of two ListBoxes (In
brief, ListBox1 consists of the available data - i.e., employee names;
ListBox2 will populate with the selected data via CommandButton1). I would
like the selected items in ListBox1 to not only populate in ListBox2 on the
UserForm1 (which Ive accomplished), but also populate ListBoxes in my Word
Report (a single item per ListBox). The code I currently have populates all
ListBoxes on my Word report with all selected items. Id appreciate any and
all advise/direction. (below youll find the most relevant code) Thank you.

Dim employees As Integer
Private Sub CommandButton1_Click()
If ListBox1.ListIndex = -1 Then Exit Sub
For employees = ListBox1.ListCount - 1 To 0 Step -1
If ListBox1.Selected(employees) = True Then
ListBox2.AddItem ListBox1.List(employees)
Report.ListBox1.AddItem ListBox1.List(employees)
Report.ListBox2.AddItem ListBox1.List(employees)
Report.ListBox3.AddItem ListBox1.List(employees)
Report.ListBox4.AddItem ListBox1.List(employees)
Report.ListBox5.AddItem ListBox1.List(employees)
Report.ListBox6.AddItem ListBox1.List(employees)
Report.ListBox7.AddItem ListBox1.List(employees)
Report.ListBox8.AddItem ListBox1.List(employees)
Report.ListBox9.AddItem ListBox1.List(employees)
Report.ListBox10.AddItem ListBox1.List(employees)
ListBox1.RemoveItem (employees)
End If
Next employees
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Listbox Output to Individual Listboxes

You sure you wanted to post this in an Excel newsgroup?

But I'd try moving the .removeitem into a different loop:

Option Explicit
Private Sub CommandButton1_Click()
Dim employees As Long

'with .multiselect = true, this won't do anything
'well, that's true in excel anyway
'If ListBox1.ListIndex = -1 Then
' Exit Sub
'End If

For employees = ListBox1.ListCount - 1 To 0 Step -1
If ListBox1.Selected(employees) = True Then
ListBox2.AddItem ListBox1.List(employees)
Report.ListBox1.AddItem ListBox1.List(employees)
Report.ListBox2.AddItem ListBox1.List(employees)
Report.ListBox3.AddItem ListBox1.List(employees)
Report.ListBox4.AddItem ListBox1.List(employees)
Report.ListBox5.AddItem ListBox1.List(employees)
Report.ListBox6.AddItem ListBox1.List(employees)
Report.ListBox7.AddItem ListBox1.List(employees)
Report.ListBox8.AddItem ListBox1.List(employees)
Report.ListBox9.AddItem ListBox1.List(employees)
Report.ListBox10.AddItem ListBox1.List(employees)
End If
Next employees

For employees = ListBox1.ListCount - 1 To 0 Step -1
If ListBox1.Selected(employees) = True Then
ListBox1.RemoveItem (employees)
End If
Next employees

End Sub

(Untested, uncompiled. Watch for typos.)


Robert D wrote:

I'm struggling to design a simple report in Word with visible CommandButtons
that will allow the user to open a UserForm, select appropriate data from
ListBoxes, and upon exiting the UserForm, populate individual ListBoxes on
the Word report. The respective UserForm1 consists of two ListBoxes (In
brief, ListBox1 consists of the available data - i.e., employee names;
ListBox2 will populate with the selected data via CommandButton1). I would
like the selected items in ListBox1 to not only populate in ListBox2 on the
UserForm1 (which Ive accomplished), but also populate ListBoxes in my Word
Report (a single item per ListBox). The code I currently have populates all
ListBoxes on my Word report with all selected items. Id appreciate any and
all advise/direction. (below youll find the most relevant code) Thank you.

Dim employees As Integer
Private Sub CommandButton1_Click()
If ListBox1.ListIndex = -1 Then Exit Sub
For employees = ListBox1.ListCount - 1 To 0 Step -1
If ListBox1.Selected(employees) = True Then
ListBox2.AddItem ListBox1.List(employees)
Report.ListBox1.AddItem ListBox1.List(employees)
Report.ListBox2.AddItem ListBox1.List(employees)
Report.ListBox3.AddItem ListBox1.List(employees)
Report.ListBox4.AddItem ListBox1.List(employees)
Report.ListBox5.AddItem ListBox1.List(employees)
Report.ListBox6.AddItem ListBox1.List(employees)
Report.ListBox7.AddItem ListBox1.List(employees)
Report.ListBox8.AddItem ListBox1.List(employees)
Report.ListBox9.AddItem ListBox1.List(employees)
Report.ListBox10.AddItem ListBox1.List(employees)
ListBox1.RemoveItem (employees)
End If
Next employees
End Sub


--

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
Deactivate individual listbox lines ZipCurs Excel Programming 2 May 3rd 07 03:36 AM
Set of varibles produces one output. Need series of output. Bernie Deitrick Excel Programming 1 January 11th 07 12:00 AM
Calculate and display individual error bars for individual points del Charts and Charting in Excel 2 March 31st 06 05:11 PM
Calculate and display individual error bars for individual points del Charts and Charting in Excel 1 March 31st 06 04:24 AM
Can I determine in which cell is a listbox postioned?Or how to get the listboxes in a certain cell? vlado_varna Excel Programming 5 April 13th 05 11:36 PM


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