Hello everyone
Please help me
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
Please help me
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