Can you help me with a quick code to migrate the list box to an excel sheet?
The name of the report
range (b8:r)
thank you for your interest
Can you help me with a quick code to migrate the list box to an excel sheet?
The name of the report
range (b8:r)
thank you for your interest
Let's see if this is what you are seeking ...
![]()
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 'Pass row & column count to variables 'Less 1 as "Count" starts at zero lRows = ListBox1.ListCount - 1 lCols = ListBox1.ColumnCount - 1 'Ensure they have at least 1 row selected For lItem = 0 To lRows 'At least 1 row selected If ListBox1.Selected(lItem) = True Then 'Boolean flag bSelected = True 'Exit for loop Exit For End If Next 'At least 1 row selected If bSelected = True Then With Sheet1.Range("D1", Sheet1.Cells(lRows + 1, 4 + lCols)) 'Transfer to range CHANGE SHEET AND RANGE HERE !!! .Cells.Clear 'Clear transfer range For lItem = 0 To lRows If ListBox1.Selected(lItem) = True Then 'Row selected 'Increment variable for row transfer range lTransferRow = lTransferRow + 1 'Loop through columns of selected row For lColLoop = 0 To lCols 'Transfer selected row to relevant row of transfer range .Cells(lTransferRow, lColLoop + 1) = ListBox1.List(lItem, lColLoop) 'Uncheck selected row ' ListBox1.Selected(lItem) = False Next lColLoop End If Next End With 'Unload Me Else ' NO listbox row chosen MsgBox "Nothing chosen", vbCritical End If End Sub Private Sub UserForm_Initialize() 'Set ListBox ColumnCount to the same as RowSource ListBox1.ColumnCount = Range(ListBox1.RowSource).Columns.Count End Sub
Why migrate the listbox info...Surely the listbox gets it's info from a sheet...So...Just migrate the sheet...
Good Luck...
I don't presume to know what I am doing, however, just like you, I too started somewhere...
One-day, One-problem at a time!!!
If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
Also....Add a comment if you like!!!!
And remember...Mark Thread as Solved...
Excel Forum Rocks!!!
thank you v much![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks