Write Listbox selection to Multiple cells

E

eklarsen

I have created a list box, I would like the selection the user clicks on
to then be copied to multiple cells.

If i could get it to write to one cell I am sure I can figure out the
rest.

When the user selects the item it is in listbox1.value and
listbox1.text but I have been unsuccesfull so far.

here is the code:

Sub RemoveDuplicates1()
Dim AllCells As Range, Cell As Range
Dim NoDupes As New Collection

On Error Resume Next
For Each Cell In Range("Data")
NoDupes.Add Cell.Value, CStr(Cell.Value)
Next Cell
On Error GoTo 0
UserForm1.Show

End Sub

I defined the worksheet and range in the listbox properties.
 
L

Leith Ross

Hello eklarsen,

Here is an example of how to set multiple cells equal to the list bo
value. The example uses a list box named ListBox1. The code in th
click event will transfer the selected list item to 3 cells o
Worksheet "Sheet1". Cells A2, B6, and C8 will equal what was seelcte
in ListBox1. You can change the ListBox and Worksheet names to what yo
are using. Just place the code in the list box's Click event.


Code
-------------------
Private Sub ListBox1_Click()

Dim Data As String

With ListBox1
Data = .List(.ListIndex)
End With

With Worksheets("Sheet1")
.Range("A2").Value = Data
.Range("B4").Value = Data
.Range("C6").Value = Data
End With

End Sub
 
Joined
Nov 11, 2017
Messages
1
Reaction score
0
Hello eklarsen,

Here is an example of how to set multiple cells equal to the list bo
value. The example uses a list box named ListBox1. The code in th
click event will transfer the selected list item to 3 cells o
Worksheet "Sheet1". Cells A2, B6, and C8 will equal what was seelcte
in ListBox1. You can change the ListBox and Worksheet names to what yo
are using. Just place the code in the list box's Click event.


Code
-------------------
Private Sub ListBox1_Click()

Dim Data As String

With ListBox1
Data = .List(.ListIndex)
End With

With Worksheets("Sheet1")
.Range("A2").Value = Data
.Range("B4").Value = Data
.Range("C6").Value = Data
End With

End Sub

-------------------

Sincerely,
Leith Ros

--
Leith Ros
-----------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=1846
View this thread: http://www.excelforum.com/showthread.php?threadid=48782

Is it possible to select different ranges at any given time instead of predefined ranges as above?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

type mismatch error 8
Time sensitive please help! 3
copy and paste 5
Excel Combobox with additional selection criteria 4
No dupes 5
duel criteria seach 1
excel - ListBox multiple Select 4
Userform 4

Top