Hi Manish ,
See if this helps :
http://dailydoseofexcel.com/archives/2004/04/27/using-multiselect-listboxes/
Narayan
Option Explicit
Sub ExtractSelected()
' constants
Const ksWS = "Sheet1"
Const kiColumn = 9
Const kiRow = 3
' declarations
Dim I As Integer, J As Integer
' start
I = kiRow
' process
With Worksheets(ksWS).ListBox1
For J = 0 To .ListCount - 1
If .Selected(J) Then
.Parent.Cells(I, kiColumn).Value = .List(J)
I = I + 1
End If
Next J
End With
' end
Beep
End Sub
Thanks a lot SirJB7,Hi, Manish Sharma!
Try this code:
Code:Option Explicit Sub ExtractSelected() ' constants Const ksWS = "Sheet1" Const kiColumn = 9 Const kiRow = 3 ' declarations Dim I As Integer, J As Integer ' start I = kiRow ' process With Worksheets(ksWS).ListBox1 For J = 0 To .ListCount - 1 If .Selected(J) Then .Parent.Cells(I, kiColumn).Value = .List(J) I = I + 1 End If Next J End With ' end Beep End Sub
Regards!
Private Sub CommandButton1_Click1()
Dim I As Long, txt As String, Flg As Boolean
Range("B10").Select
Range(Selection, Selection.End(xlToRight)).ClearContents
With Me.ListBox1
For I = 0 To .ListCount - 1
If .Selected(I) Then
Flg = True
txt = txt & "," & .List(I)
End If
Next
End With
If Flg Then
With Sheets("Sheet1")
.Range("b10").Value = Mid$(txt, 2)
End With
End If
'This is to get the selected options from ListBox in seperate cells
Selection.TextToColumns Destination:=Range("B10"), DataType:=xlDelimited, Comma:=True, TrailingMinusNumbers:=True
End Sub
With Worksheets(ksWS)
Range(.Cells(kiRow, kiColumn), .Cells(.Rows.Count, kiColumn)).ClearContents
End With