Transfer Specific Column From ListBox Userform

IoanZ

Board Regular
Joined
Mar 2, 2018
Messages
51
Hello everyone
Please help me
vwecgqX

I use this code to transfer in cell D1/E1/F1 the selected values from listbox userform.
With this code i can transfer all columns from selected row

Which is vba code to transfer in cell D1/E1 only the first and third columns of selected row from listbox.
(i want to put in cell D1 Num value and in cell E1 Day value)
Image of sheet.
https://imgur.com/a/vwecgqX

Thanks a lot

Private Sub TransferButton_Click()
Dim lItem As Long, lRows As Long, lCols As Long
Dim bSelected As Boolean
Dim lColLoop As Long, lTransferRow As Long
lRows = ListBox1.ListCount - 1
lCols = ListBox1.ColumnCount - 1
For lItem = 0 To lRows
If ListBox1.Selected(lItem) = True Then
bSelected = True
Exit For
End If
Next

If bSelected = True Then
With Sheet1.Range("D1", Sheet1.Cells(lRows + 1, 4 + lCols)) 'Transfer to range
.Cells.Clear 'Clear transfer range
For lItem = 0 To lRows
If ListBox1.Selected(lItem) = True Then 'Row selected
lTransferRow = lTransferRow + 1
For lColLoop = 0 To lCols
.Cells(lTransferRow, lColLoop + 1) = ListBox1.List(lItem, lColLoop)
Next lColLoop
End If
Next
End With
Else
MsgBox "Nothing chosen", vbCritical
End If
End Sub
vwecgqX
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Try this:

Code:
Private Sub TransferButton_Click()
    If ListBox1.ListIndex = -1 Then
        MsgBox "Nothing chosen", vbCritical
    Else
        Sheet1.Range("D1").Value = ListBox1.List(ListBox1.ListIndex, 0)
        Sheet1.Range("E1").Value = ListBox1.List(ListBox1.ListIndex, 2)
        MsgBox "Transferred data", vbInformation
    End If
End Sub
 
Upvote 0
I found this code and works fine (for multiple selection from listbox

Private Sub CommandButton6_Click()
Dim lngItem As Long
For lngItem = 0 To ListBox2.ListCount - 1
If ListBox2.Selected(lngItem) Then
With Sheets(1) '< qualify sheet here
.Cells(Range("C423").End(xlUp).Row + 1, 3).Value = ListBox2.List(lngItem, 0)
.Cells(Range("D423").End(xlUp).Row + 1, 4).Value = ListBox2.List(lngItem, 2)
End With
End If
Next lngItem
Unload Me
ActiveSheet.Calculate
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,183
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top