Macrol to select mutiple items from a list box and paste selected items in horizontally consecutive cells

Tanner_2004

Well-known Member
Joined
Jun 1, 2010
Messages
616
I am using 2010 and want to select nultiple states (locations) from a list box (would that have to be an Active X control?), then paste the selections along a row in adjacent consecutive cells.

For example, my list box would present the user with 51 states. The user would select muluple states by holding down the control key and left clicking, the selected states would change color (click again to unselect), then each selected state would be pasted started in J10, H10, I10 etc.


Any ideas?

Thank you for reading!

Best,

Tony
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Wow...get me started. You did it. Thank you! Exactly what I needed!

I am a huge dog fan. I own two golden retrievers and we foster some to help people with speacial needs. I will send you my LinkedIn emal address is you wou want to connect. Thank you very much!

Very handsome dog. My good friend breeds the real German shepards from Germany (not the American versions). I never knew their were two versions.

Tony


Hi, :)

maybe that leads you in the right direction:

here is a sample file.
 
Upvote 0
I just sent you a PM. but I tjought I would post my additional question for others to benefit.

I just want to clear G27 to BD27 - not the entire row 27.

How woudl you change this please?
Private Sub CommandButton1_Click()
Dim intCount As Integer
Dim lngTMP As Long
On Error GoTo Fin
' This deposits the value in column G or the 7the column
lngTMP = 7
'This deposits the first value in row 27
Me.Rows(27).ClearContents
With Me.ListBox1
For intCount = 0 To .ListCount - 1
If .Selected(intCount) = True Then
Me.Cells(27, lngTMP).Value = .List(intCount)
lngTMP = lngTMP + 1
End If
Next intCount
End With
Fin:
If Err.Number <> 0 Then MsgBox "Error: " & _
Err.Number & " " & Err.Description
End Sub



Hi, :)

maybe that leads you in the right direction:

here is a sample file.
 
Upvote 0
Hi, :)

just write...
Code:
Me.Range("G27:BD27").ClearContents

Or - the better way - defining a name like "MyRange" and then write:
Code:
Me.Range("MyRange").ClearContents
 
Upvote 0
Thank you. I was missing the "Range" term. I can't tell you how many books (just bought another one last night) and DVDs I own and I still can't get my arms around this. Thank you again!

Hi, :)

just write...
Code:
Me.Range("G27:BD27").ClearContents

Or - the better way - defining a name like "MyRange" and then write:
Code:
Me.Range("MyRange").ClearContents
 
Upvote 0
Is it easy to write a macro that will allow the user to clear all of the locations that he/she selected, in addition to the option of deselecting the locations by clicking on the selectiosn again? Thank you.
 
Upvote 0
Hi, :)

here are two ways to remove the marking of the entries in the ListBox. Once a mouse double click. In the second example, you have to press 0 on the keyboard - it also does the 0 on the numeric keypad.

Sample 1

Sample 2
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,269
Members
449,075
Latest member
staticfluids

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