select items in a list box with a macro?

Instead of a mouse, can you select items in a list box with a macro?
0
Fan924
1/11/2010 6:41:28 PM
excel.programming 6508 articles. 2 followers. Follow

3 Replies
1424 Views

Similar Articles

[PageSpeed] 11

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
0
Dave
1/11/2010 8:19:14 PM
> 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?
0
Fan924
1/12/2010 8:47:47 AM
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
0
Dave
1/12/2010 1:42:29 PM
Reply:

Similar Artilces:

Lists Questions
i have a list that i have 10 different accounts listed in on my form. I have it setup so that i can select multiple options. how do i get this list to show up in the actual table? I had to create this list on the form itself. is there a way to take that list that i made and convert it into a text field when i run a report? and have it display what was selected? Are you trying to put multiple accounts in the same table field? That doesn't seem right. A multi select list box will not return a value if you use it like Me.txtAccount = Me.lstAccountList You have to loop through the Item...

Macro Help Please excel 2003
I need a button so that when pressed it exports the data from the cell range sheet 1: A21:S81, it also exports the info from the same range A21:S81 on sheet 2 to an external excel workbook. I need it to export all the data onto sheet 1 of the external workbook, and each time the button is pressed it needs to find the first available row of the external workbook and copy over, this is so that all data is always saved on a massive long list. Thanks Neil. let us stick on to the original post. I have posted a response for your latest request. -- Jacob "Neil H...

how to create a dynamic descending list of months & years
I'm trying to create a spreadsheet whereby in cell A1 I enter in any given Month and Year ("January 2005", formatted as a date), and in cells B1:J1 the previous months and years show up (December 2004; November 2004; October 2004; etc....) If I type in "April 1985", the adjacent cells would read "March 1985; February 1985; January 1985; December 1984; etc... I've thought of a couple laboriuos, crude, potentially faulty ways of doing this, but it seems like there should be an eloquent solution. Very much appreciated!!! Marika :) Can you put the followi...

Printing problem when selecting any paper type other than plain pa
I have MSPub 2002 with XP HE and use an HP Inkjet printer cp1700. When I make my brochures I usually put a border around the edge a fill with some color. If I print one page, I have no problem, but if I ask the software to print numerous copies (anything more than 1 such as 2,3,4,etc) when it prints the second, third, forth etc copy, I always get a series of 3 lines after the top border. If I click the printer icon numerous times I do not get this problem or if I print the document in "paper type" plain paper, I do not get the problem. Does anyone ever experience this problem...

MS supplies 64 bit printer driver does not select paper tray
Win7 Home Premium 64 bit LexMark T420 printer (Lan connected) Win7 saw the printer and loaded a MS driver for it. I can print to the T420 but the print out always goes to tray 1 (legal). In the print preferences panel, I select tray 2 but the physical print always comes from tray 1. I cannot tell if the MS driver is PS or PCL. This is my first foray into the world of 64 bit printer drivers. Any suggestions appreciated. -- ***************** John Lenz JohnLenz@comcast.net The drivers provided by Microsoft are supplied by the manufacturer and are almost always not fu...

templates in folder list in Outlook 2002
I was wondering if anybody has figured out a way to get templates to appear in the folder list using Outlook 2002. I have numeous templates that I use daily and having them in the folder list would be so much easier than the 'choosing form' dialog box each time. Thanks. ...

Recover Deleted Items in Outlook 2000
I recently had a user that lost all items in the "Deleted Items" folder and needs to rocover them. I am using Outlook 2000 and wouls appreciate any information on how or where to view these items. Do you use Exchange server? If so, and it's configured for deleted item retention, you can get the items back if they were deleted within that time frame (however long retention is set for). If you don't use Exchange server, or even if you do and you use PST files for delivery (ick), you may be out of luck - but see http://www.outlook-tips.net/howto/recover_deleted.htm for one pos...

'Item could not be found" and auto hypen between phone no's
1.Cannot send email with attachments to a distribution list of names because error message pops up.."The item could not be found." Note: works fine if sending to a single contact recepient. 2. In Outlook program of Office 2000 used to be able to type in 14556789 and it would automatically put in the hypens as 1-455-6789. Why not now in Outlook 2002? ...

Customizing the "Details:" list for an entity?
I've created my own custom entities as an alternative to the default Product and Opportunity Product entities. This is because the whole price-list model doesn't fit my organization at all, and I can't seem to remove those attributes/relationships. So now, the Details: list for an Opportunity looks like this: Details: - Information - Products - Relationships - Sales Process - Activities - History - My Custom Opportunity Products Questions: 1) How do I rename that last entry, which is the relationship to my custom entity? 2) How do I move it up in the list? 3) How do I rem...

Problem with List Control Box
I have a list control with 3 columns. For some reason when I try to insert an entry into the list control, sometimes, only the item's first value gets added, but the values for the 2nd and 3rd column are not there. If i continue to add the same entry consistently, eventually the entry will be added correctly with all three values. Why is that? For example: sometimes I will add (a,b,c) into my List control box, but only (a) gets shown. But if i keep inserting an item, eventually the entry (a,b,c) will be added... >I have a list control with 3 columns. For some reason when I try ...

Criteria for select query.
I have Access2003. I need a criteria expression to select certain data from a query QryLedgerTxns. When the ledger is reconciled with the bank statement, that statement date is manually entered into a QryLedgerTxns field called "DateStatement". The "DateStatement" field matches a ledger transaction field called "Withdrawal" My aim is to add up all the sums in the "Withdrawal" field *not* reconciled with the bank statement. The "Withdrawal" field is currency. The "DateStatement" field is Date/time. Therefo...

GP should allow you to create a return for drop ship items!
What is the reason behind not being able to create a return for drop ship items? Do you think customer who receive their product via drop ship never have to return an item? This is really short sided on your part. 95% of our business is drop ship and we have return all the time. ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow this link to open the suggestion in the Microsoft Web-based Newsread...

selecting cells #3
When working with a large group of cells, I find it easier to click the top cell, scroll to the bottom, and click the last cell while holding the shift key down. The problem is, when I want to select a second column of data, I have to select the top cell using the control key, the pull down the cursor manually. Is there a way to select 2 or more non-adjacent columns without having to scroll down using the mouse? Nevermind - figured it out myself. The easiest things are often so obvious they are hard to see. "Wazooli" wrote: > When working with a large group of cells, I...

Create list to choose from
Hi, I'm just trying to create a short pulldown list in a spreadsheet. Instead of having to retype repetitve selections for this spreadsheet that gets used a lot, I'd like to create a pulldown list, but I'm not sure which kind of list to choose and I'm not sure how to enter the list. Can anyone help. Thanks a bunch. Diana Hi Dianah i'ld go with data / validation check out Debra Dalgleish's site for details http://www.contextures.com/xlDataVal01.html cheers JulieD "Dianah" <nospam@nospam.com> wrote in message news:OLWdR3GWEHA.2716@tk2msftngp13.phx....

Item 'Last Ordered' Field updates inappropriately
The 'Last Ordered' field updates when I transfer inventory out. This is not good. If I want to know the last time I bought an item, the date of the most recent transfer does not help - especially if it was an inter-store transfer out. Ideally, separate fields for 'Last Transferred In' and Last Transferred Out' could be added as separate fields. This would reserve the 'Last Ordered' field for the last time the item was actually ordered from a supplier. Alternately, and better thant the present system, the field could simply update with purchase orders ONLY...

Global Adress list not updating
Outlook Global Address List in Outlook is not updating when users are added or deleted in Active directory. I have clicked on "Update Now" under Recipient Update Service In Exchange System Manager. This does not update the list. Any ideas anyone? Which version of Exchange? Which version of Windows? Which version of Outlook? E "Brendon" <anonymous@discussions.microsoft.com> wrote in message news:045601c3c42e$bb8ee630$a401280a@phx.gbl... > Outlook Global Address List in Outlook is not updating > when users are added or deleted in Active direct...

List Webpart Installs fine, but crashes Sharepoint
Ok, I read the readme, and see that others have had trust delegation issues. I have a single SBS 2003 server. When I install the CRM Webpart, go to Sharepoint and add the webpart to the home page, subsequent visits give me a Sharepoint Timeout error. When I uninstall the list webpart, the company webpage comes back up fine. Where would I find a log file or something to help diagnose this? I've googled the issue and can't find anyone else having this problem. Any other ideas? Thanks, James ...

Excel Combo Box #2
I have created an Excel Combo Box that include ten different selections. The combo box is linked to a cell. I want the selection in the combo box displayed in the linked cell. What I get know is the line number. How do I correct this? Instead of using the combo on the forms toolbar, try using the combo on the control toolbar (View/Toolbars/Control Toolbox) and then set the look up range and linked cell from the combo's properties. HTH Paul >-----Original Message----- >I have created an Excel Combo Box that include ten >different selections. The combo box is linked ...

Chart item reports with OUTLOOK via Excel or ?
I want to create reports for OUTLOOK items (particularly tasks). I'd like to be able to see charts that display things like the amount of time spent on tasks for various clients, the type of work done, and the dates (including time of day). I'd like to be able to look at these reports daily if possible. Is there a way that I can do this? I thought that there must be a way by exporting the items into excel then manually setting up charts but this would be time consuming to do each time. Any help is appreciated (I've spent days trying to figure this out) ...

Data Validation
What I am trying to achieve is a drop down list that would look something like this: D1a - suipplies F1g - cell phones C2a - travel E4b - computers and so on and so forth. I can do that. What I would like to happen though is in the same cell that the drop down box is in (a29) I would like to select one of those options and only have D1a, or F1f, ect show up in the cell. The words are just references to my budget, and I don't nned them after I selected the right one. Is this possible? I am somewhat new to excel and have never went into the visual basic editor and I don't have...

create new mail item from current item
Greetings, How can I create a new mail item from the active inspector current item? Thank you, Please provide more details on what you want to do. In other words, what does the current item have to do with the new item you want to create? -- Sue Mosher, Outlook MVP Author of Microsoft Outlook 2007 Programming: Jumpstart for Power Users and Administrators http://www.outlookcode.com/article.aspx?id=54 "lindstrom" wrote: > Greetings, > How can I create a new mail item from the active inspector current item? > Thank you, > > --- > fr...

Deleted items
I'd like for my deleted items to be listed in date order when deleted rather than the date they were originally received. ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow this link to open the suggestion in the Microsoft Web-based Newsreader and then click "I Agree" in the message pane. http://www.microsoft.com/office/community/en-us/default.mspx?mid=d66c023f-3eed-461f-bfa3-01769e...

combobox list in userform
Hi How do I compile the list for a combobox? Where do I put it? -- robzrob You put it in code. When the form initializes, use either the AddItem method or the List property to set the rows. -- Sue Mosher, Outlook MVP Author of Microsoft Outlook 2007 Programming: Jumpstart for Power Users and Administrators http://www.outlookcode.com/article.aspx?id=54 "robzrob" wrote: > Hi > > How do I compile the list for a combobox? Where do I put it? > -- > robzrob ...

Formatting within this macro
I am new to VBA and can follow along fairly well, but don't know how to do certain things. I have the following macro that runs like a champ, but now I need to automatically format the SummarySheet. Specifically, I need to set Columns A,C,E and G to a width of 2 and to have a color of Light Gray (in Office 2010 it's White, Background 1, Darker 25%). I also need to set Rows 1 and 3 to a height of 6 and have a color of Light Gray. Then I need to change the output font to Tahoma, 12, Bold. Finally, I have to have a cell at the bottom of Column F that says "Totals&q...

moving deleted items to a new folder disappear-why?
I want to move deleted items to a new "deleted item folder"i.e "deleted 021910. When I perform this step-many times the deleted items that I think move actually disappear. Where do they go? Why does this happen? At the same time a "new message" opens up looking for me to send an e-mail to some one and attached to this "new message" are multiple attachments. this is really stange. I need help. Craig "craigandmel" <craigandmel@discussions.microsoft.com> wrote in message news:4E2C3AAF-0433-41E2-A5D4-2803C3F44D86@mic...