Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 238
Default select items in a list box with a macro?

Instead of a mouse, can you select items in a list box with a macro?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default select items in a list box with a macro?

You can use a line like this:

Me.ListBox1.ListIndex = 0

The first item in the listbox is item 0.

If you allow multiple selections, then this worked ok for me:

Option Explicit
Private Sub CommandButton1_Click()

Dim iCtr As Long
With Me.ListBox1
For iCtr = 0 To .ListCount - 1
If iCtr = 0 _
Or iCtr = 3 _
Or iCtr = 5 Then
.Selected(iCtr) = True
Else
.Selected(iCtr) = False
End If
Next iCtr
End With

End Sub
Private Sub UserForm_Initialize()
Dim iCtr As Long

With Me.ListBox1
.MultiSelect = fmMultiSelectMulti
For iCtr = 1 To 10
.AddItem "A" & iCtr
Next iCtr
End With

End Sub




Fan924 wrote:

Instead of a mouse, can you select items in a list box with a macro?


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 238
Default select items in a list box with a macro?

Me.ListBox1.ListIndex = 0

Nice. I used it to scroll through the list with a small wait in
between.

Can I pull focus on the listbox and use the keyboards up & down
arrows. Is that programmable?
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default select items in a list box with a macro?

I'm not sure what pull focus means (.setfocus???), but you can change the top
item that you see in the listbox with a line like:

Me.ListBox1.TopIndex = 5
(0 is still the first item.)

Fan924 wrote:

Me.ListBox1.ListIndex = 0


Nice. I used it to scroll through the list with a small wait in
between.

Can I pull focus on the listbox and use the keyboards up & down
arrows. Is that programmable?


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Drop Down List - Select Multiple Items VLH Excel Worksheet Functions 14 October 16th 18 01:55 PM
How to Pre-Select items in Multi-Select List on Form MikeZz Excel Programming 2 August 6th 09 06:33 PM
Hi-lighting items in a multi-select List box Dan Excel Programming 6 June 4th 07 10:44 PM
select multiple items from a dropdown list Rebecca1 Excel Worksheet Functions 0 July 17th 06 08:47 PM
Create a macro to select items from an existing list .... Marc Excel Programming 3 January 6th 05 03:31 PM


All times are GMT +1. The time now is 04:20 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"