Slecting data from a ListBox

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,347
Office Version
  1. 365
Platform
  1. Windows
I have code that pulls the multiselections from my ListBox and places them in column AA. Right now its pulling the data from the first row in my listbox. (the listbox shows all the data from RowSource:='Pricing Summary'!A9:L200) When the user selects items from the listbox I need the data in the second column fo the kist box to be stored in column AA.

Is there a way to do this? Or do I need to change the order the list box is showing the data and put the data I need to go in column AA be the whats showing in the first column of the TextBox.

Dim Msg As String
Dim i As Integer
Dim NextRow As Long

Worksheets("Tables").Select
' Clear Cells First
Range("AA1:AA200").Select
Selection.ClearContents

Range("AA1").Select
' Determine the next empty row
NextRow = Application.WorksheetFunction. _
CountA(Range("AA:AA")) + 1
' Transfer the name
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) Then
Cells(i + 1, 27) = ListBox1.List(i)
End If
Next i
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Try:-
Code:
Cells(i + 1, 27) = ListBox1.List(i, 1)
You don't seem to have sorted the "lastrow" bit out.
With the code above, if you selected non contiguious Listbox rows they will show as such in "AA".
You could do something Like:-
Code:
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) Then
c = c + 1
Cells(Lastrow+c, 27) = ListBox1.List(i, 1)
End If
Next i
Mick
 
Upvote 0
Mick;

I used your suggestion and it works perfectly for what I need to do. THANKS! Much appreciated!
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,285
Members
452,902
Latest member
Knuddeluff

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