LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default Listbox

Gilbert,

I often use the GetSelected function to retrieve a 1-based 1-dimensional
array of the selected items from a listbox.

Works on all variants of multiselect
Returns an empty variant if no item is selected.
Optionally you can specify which column to return
(1st column = 0)

you can use it like:
'---------------------------------------------------------------
Private Sub CommandButton1_Click()
Dim s
s = GetSelected(Me.Controls("Listbox1"))
If Not IsEmpty(s) Then
Worksheets(s).Select
ActiveWindow.SelectedSheets.PrintOut
End If
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

Suc6!

keepITcool

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


"Gilbert Aponte" wrote:

I have created a listbox which displays all the sheet
within my workbook. I have added a check box to allow the
user to move from one sheet to the other within the
listbox. I have also added a check box to allow the user
to print the active sheet only. All works well.

However, I want to be able to tag whatever sheets that is
displayed within the same listbox, using the same print
check box and print all the user selected sheets.

Can anyone help me out with this function...


 
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
Listbox 2 takes the value of Listbox 1 Illya Teideman Excel Discussion (Misc queries) 3 April 10th 07 03:20 PM
listbox B conditional of input in Listbox A Kim K Excel Discussion (Misc queries) 1 October 31st 06 08:27 PM
Listbox B if LIstbox A equals Kim K Excel Discussion (Misc queries) 2 October 31st 06 07:03 PM
Is refreshing listbox rowsource in listbox click event possible? Jeremy Gollehon[_2_] Excel Programming 4 September 25th 03 06:45 PM
Sorting ListBox results or transposing ListBox values to other cells for sorting Rob[_8_] Excel Programming 1 July 9th 03 04:35 AM


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