Displaying listbox selection in textbox

I av a problem trying to create a macro that the selection made in 
listbox(List1) to be displayed in a textbox(Text1).

here is the code that i did so far but i cant get it to work:

Sub Expense_Select()

'Link the data to the listbox
Range("G7:G18").Select
ActiveSheet.Shapes("List1").Select

With Selection
.ListFillRange = "$G$7:$G$19"
.LinkedCell = ""
.MultiSelect = xlNone
.Display3DShading = False
End With

End Sub

Private Sub List1_Click()

'display the selected item in the textbox
Text1.Text = List1.List(List1.ListIndex)

End Sub

ANY suggestions would be helpful Cheers :

--
Message posted from http://www.ExcelForum.com

0
6/19/2004 5:21:45 AM
excel.misc 78881 articles. 5 followers. Follow

1 Replies
1254 Views

Similar Articles

[PageSpeed] 22

If you're allowing multiple selections in the listbox, you may not want to
display the selected items in a textbox.  Maybe a second listbox would work ok.

Are these controls on a UserForm on directly on a worksheet?

If it's on a userform, then you can read this:
http://groups.google.com/groups?selm=3FF0C690.BE11BDD4%40msn.com

If they're on a worksheet, then I used controls from the Control Toolbox
toolbar.  I put 4 commandbuttons and two listboxes on the worksheet.  Then I
named the Commandbuttons:

BTN_moveAllLeft
BTN_moveAllRight
BTN_MoveSelectedLeft
BTN_MoveSelectedRight

Right click on the worksheet tab and select view code.  Paste this in:

Option Explicit
Private Sub BTN_moveAllLeft_Click()

    Dim iCtr As Long
    
    For iCtr = 0 To Me.ListBox2.ListCount - 1
        Me.ListBox1.AddItem Me.ListBox2.List(iCtr)
    Next iCtr
    
    Me.ListBox2.Clear
End Sub
Private Sub BTN_moveAllRight_Click()

    Dim iCtr As Long
    
    For iCtr = 0 To Me.ListBox1.ListCount - 1
        Me.ListBox2.AddItem Me.ListBox1.List(iCtr)
    Next iCtr
    
    Me.ListBox1.Clear
End Sub
Private Sub BTN_MoveSelectedLeft_Click()

    Dim iCtr As Long
    
    For iCtr = 0 To Me.ListBox2.ListCount - 1
        If Me.ListBox2.Selected(iCtr) = True Then
            Me.ListBox1.AddItem Me.ListBox2.List(iCtr)
        End If
    Next iCtr
    
    For iCtr = Me.ListBox2.ListCount - 1 To 0 Step -1
        If Me.ListBox2.Selected(iCtr) = True Then
            Me.ListBox2.RemoveItem iCtr
        End If
    Next iCtr

End Sub
Private Sub BTN_MoveSelectedRight_Click()

    Dim iCtr As Long
    
    For iCtr = 0 To Me.ListBox1.ListCount - 1
        If Me.ListBox1.Selected(iCtr) = True Then
            Me.ListBox2.AddItem Me.ListBox1.List(iCtr)
        End If
    Next iCtr
    
    For iCtr = Me.ListBox1.ListCount - 1 To 0 Step -1
        If Me.ListBox1.Selected(iCtr) = True Then
            Me.ListBox1.RemoveItem iCtr
        End If
    Next iCtr

End Sub
Private Sub Worksheet_Activate()
    
    Dim myCell As Range
    
    Me.ListBox1.Clear
    Me.ListBox2.Clear
    With Me.ListBox1
    
        .LinkedCell = ""
        .ListFillRange = ""
        
        For Each myCell In Me.Range("g7:g19").Cells
            If Trim(myCell) <> "" Then
                .AddItem myCell.Value
            End If
        Next myCell
        
    End With
    
    Me.ListBox1.MultiSelect = fmMultiSelectMulti
    Me.ListBox2.MultiSelect = fmMultiSelectMulti
        
End Sub

The bad news is I wasn't sure when to populate the listbox.  I chose to do it
when you activated the worksheet.  I don't think you'd want this--if you click
off the sheet and come back, then the listboxes are reset.

Maybe have it populated when the workbook opens????


"steve411 <" wrote:
> 
> I av a problem trying to create a macro that the selection made in a
> listbox(List1) to be displayed in a textbox(Text1).
> 
> here is the code that i did so far but i cant get it to work:
> 
> Sub Expense_Select()
> 
> 'Link the data to the listbox
> Range("G7:G18").Select
> ActiveSheet.Shapes("List1").Select
> 
> With Selection
> ListFillRange = "$G$7:$G$19"
> LinkedCell = ""
> MultiSelect = xlNone
> Display3DShading = False
> End With
> 
> End Sub
> 
> Private Sub List1_Click()
> 
> 'display the selected item in the textbox
> Text1.Text = List1.List(List1.ListIndex)
> 
> End Sub
> 
> ANY suggestions would be helpful Cheers :)
> 
> ---
> Message posted from http://www.ExcelForum.com/

-- 

Dave Peterson
ec35720@msn.com
0
ec35720 (10082)
6/19/2004 6:21:12 PM
Reply:

Similar Artilces:

after crash forms display #NAME?
Hello, I was working on my Db when all of a sudden it crashed. I saved a backup and closed it down. I opened the back up and now on my main " Job Information" form, almost all of my text boxes with equations display "#Name?". Some of the text boxes reference other tables, some other forms, and some the same form they are located on. I checked the data source an a select few boxes and all the data, according to my table, is correct. Its worth noting that the entire DB was working perfectly before this crash. Now if i go into design mode for the form, delete any t...

Displaying a List of All VBA Procedures in Excel 2007 fromthe Ribb
How can I make this available to any workbook. For instance, I have a system running and it has around 280 modules. you might see the code at: http://msdn.microsoft.com/en-us/library/dd890502(office.11).aspx or bellow: Option Explicit Private Sub btnClose_Click() Unload Me End Sub Private Sub btnList_Click() ' Declare variables to access the Excel 2007 workbook. Dim objXLApp As Excel.Application Dim objXLWorkbooks As Excel.Workbooks Dim objXLABC As Excel.Workbook ' Declare variables to access the macros in the workbook. Dim VBAEditor ...

Issues with Select statement doing 'simple' math
Hello, I have tried numerous solutions to what should be a simple issue, but I have had no success. I am trying to gather some simple math values from a single table, and I cannot create the proper select statement. The below query works and provides the correct values: SELECT TOP (100) PERCENT MAX(DistCode) AS DistCode, MAX(DistName) AS DistName, MAX(CustServRep) AS CustServRep, COUNT(DistCode) AS AllOrders FROM dbo.[TABLE OrderHistory] AS OH WHERE (M2K_Timestamp >= CONVERT(DATETIME, '2010-03-01 00:00:00', 102)) AND (M2K_Timestamp < CONVERT(DATETIME, '...

Validate almost one of two textbox
Hi, how can I validate a group of 2 textbox so the users have to populate at least one of them (or both)? Thanks in advance. Luis On Nov 27, 2:16=A0pm, Luigi <Lu...@discussions.microsoft.com> wrote: > Hi, > how can I validate a group of 2 textbox so the users have to populate at > least one of them (or both)? > > Thanks in advance. > > Luis Use Javascript Function function jsValidateTextBoxGroup(sTxtBox1, sTxtBox2) { var bSuccess =3D true; var sTxtBox1Value =3D document.getElementById(sTxtBox1).value; var sTxtBox2Value =3D document.g...

How do you select a cell with an "absolute" address with a cursor?
When you try to make an absolute reference to a cell, you place "$" in front of the column and/or row. But can you do it more easily by, for example, selecting a cell with your mouse while pressing CTRL (obviously this does not work) when you select a cell? Thank you. New Daddy, select the cell press F2 then F4 to toggle absolute -- Paul B Always backup your data before trying something new Please post any response to the newsgroups so others can benefit from it Feedback on answers is always appreciated! Using Excel 2002 & 2003 "New Daddy" <newlywed2@daum.net>...

How do I delete selected cell when using check box
I have data in rows A17:J500 with check boxes in rows J17:J500 By activating a macro in A10 I want to clear contents of selecte rows. Thank you -- Message posted from http://www.ExcelForum.com Use Range("A17:J500").ClearContents How do you activate the macro in A10, by selecting A10? Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Target.Address = "$A$10" Then Application.DisplayAlerts = False Range("A17:J500").ClearContents Application.DisplayAlerts = True End If End Sub -- No private emails please, for everyone'...

select case
Hi I have various cells on a worksheet in different rows that is linked to a vba case selection, whereby rows are hidden or not based on the drop down selection in those cells. The problem that I have is that the user has the option to insert rows in between these cells which will have the effect that the wrong row ranges will now be hidden or not as the rows now move downwards depending on how many rows are inserted. Is there a way of ensuring that the range selection as per the vba moves downwards as and when rows are being inserted? Hein As ALWAYS, post YOUR code for com...

DLookUp or SELECT
I have a table of EMPLOYESS (tblEmployees). Fields are EmployeeID; FirstName; LastName. I have another table of ACTIVITIES (tblActivities). One of the fileds in the tblActivities table is PersonID which contains the number of the EmployeeID in the tblEmployees table. I want the resulting "match" between the [tblActivities.PersonID] and [tblEmployees.EmployeeID to populate a Text Box with the results of this "equal compare" AND INCLUDE the FirstName and LastName fields. I am lost as to how to do this. Create a query based on TblEmployees and TblActivit...

Displaying the zero value in a cell
Is it possible to display a zero at the front of a series of numbers in a cell? Eg. "0123" is displayed as "123". How to display as original "0123"? I've got the 'zero value' checked in Tools - Options - View. That is only for a zero value in a cell without any other numbers in that cell. Thanks in advance!! Sure. Just type it with an apostrophe in front, or format the cells. For a good example, choose Format-Cells, Number tab. Then choose Special-->Zipcode. It shows "00000". So if your numbers are 10-digit account numbers, put "...

Problem displaying data in a Editbox
Hello. I am trying to display serial data in Edit box. The serial handler code is obtained from http://www.codeproject.com/KB/system/serial.aspx. In the serial handler, I use the SetwindowText to display the string but instead I get an occasional first character being displayed in the edit box instead of the full string. I have set the edit box properties with multiline, auto vertical scroll, want return, read only. I have also debug the code and place the string in the watch window and it seem to receive the full character on-screen. Any help please. Thanks Paul <eziggurat@gmail.com...

Linked Images (Cheks) Don't Display Properly
Hello, for some strange reason, when I choose to link an image to a transaction, most of what was downloaded shows properly. But the check images themselves does not show. In the recent past this was not a problem. I have checked the associations settings for html etc and set them to view in IE but this did not fix the problem. What am I missing, Please? ...

Add text to a field based on a combo box selection
I'm making a form that contains a dropdown field (dropdown1) containing 5 possible selections. Based upon what the user selects, I want to fill a second field (text3) with a corresponding value. For instance: If dropdown1="Maintenance" then enter "Jack Doe" text3 If dropdown1="Safety" then enter "Tom Collins" text 3 etc. Is there a way to write a 'if then else' formula in a 'calculate' form field? And if so what would the syntax be? Or is there a better (easier, non-programatic) way to accomplish this? I'm not...

Display Array from VBA
Hi: At the end of a VBA macro I have a set of results saved in an array e Results (1 to 100). How do I display the results in a specified range in a worksheet? I can do it by looping through and doing each one at a time but wha line of code would do it in one go (if there is one)? Thanks Bil -- Message posted from http://www.ExcelForum.com Hi Bill, Try: Sheets(1).Range("A1").Resize(100,1)=Results --- Regards, Norman "BillS >" <<BillS.163hnd@excelforum-nospam.com> wrote in message news:BillS.163hnd@excelforum-nospam.com... > Hi: > > At the en...

Cash flow forecast chart does not display
Recently my cash flow forecast would not display. I googled the issue and found a solution which sounded reasonable: http://groups.google.com/group/microsoft.public.money/browse_thread/thread/6ab159f49fe90e58/84f31b41ac5d1529?lnk=st&q=microsoft+money+cash+forecast+will+not+open&rnum=2&hl=en#84f31b41ac5d1529 However, I was disappointed when the problem persisted even after following the instructions which had to do with a possible broken bill or deposit. All scheduled bills and deposits were deleted and the cash flow forecast did not correct itself. I figured out what was causing...

How do i make my picture size display in inches rather than cms?
I have inserted an image into exel. I need to resize it to match another image in another program that displays the size as inches. However the Excel image size menu shows the size in centimeters. How do I make it display as inches? Grouge This is a Windows OS setting, not an Excel setting. You would go to Windows Control Panel>Regional and Language Options>Regional Options tab>Customize and set the "measurement system" to U.S. This option will affect all programs. Gord Dibben Excel MVP On Wed, 2 Mar 2005 10:51:04 -0800, Grouge <Grouge@discussions.microsoft.c...

Display GUID
How are you able to view the GUID for each field in MSCRM? Please advise. Thank you in advance for your help. Cayla what are you trying to achieve? Trying to understand what your looking for. -- John O'Donnell Microsoft CRM MVP http://www.mscrmfaq.us "Cayla" <Cayla@discussions.microsoft.com> wrote in message news:7D16B9F7-BD48-44B2-B3BA-576D072AB39B@microsoft.com... > How are you able to view the GUID for each field in MSCRM? > > Please advise. > > Thank you in advance for your help. > Cayla ...

why are my pages displaying in different widths?
I have my documents in landscape, but halfway through the document, the pages switch to a narrower landscape format than the rest. You must have a Section Break in there somewhere with different page setups for some of the Sections in the document. -- Hope this helps. Please reply to the newsgroup unless you wish to avail yourself of my services on a paid consulting basis. Doug Robbins - Word MVP, originally posted via msnews.microsoft.com "woelke" <woelke@discussions.microsoft.com> wrote in message news:581F1425-8EAB-4D50-96E8-6E0472389A0D@microsoft.com....

Publishing to Web
I published my website to web then uploaded the index.htm file and created directory for the index_files then uploaded all of the files created by Publisher 2003 to it. However, none of my graphics will display on the website. All that is displayed are the alternate text. The url for this is wsitinc.com Can some one help explain what I did wrong and where to put the graphics to get them to display? thanks! > I published my website to web then uploaded the index.htm > file and created directory for the index_files then > uploaded all of the files created by Publisher 2003...

Outlook 2007 Display Font
Is there a way to change the Outlook 2007 display font? I am talking about the font the program uses for general display, menus, etc. I have finally been able to turn off the clear type, but the font is different than what is used on the rest of the computer. It appears to be something similar to a calibri, but it is difficult to read. The rest of the computer uses Tahoma and is just fine. To test this, I changed the computer font to Times New Roman, and almost everything changed except Outlook 2007. -- Thank you, John Gregory "JGreg7" <JGreg7@discus...

OWA (Exchange 2003) Japanese characters not displayed correctly
I am currently running W2K3 with E2K3sp1. I have several Japanese officers in the company that use the Japanese OS and when they are using OWA to check e-mails the japanese characters in the body of the message do not display correctly. When you view the html code the characters are correct. Any ideas? Tom ...

formatting textboxes
I populate textboxes on a userform with the following code Private Sub cmdEditChemical_Click() Dim Chemical As Variant Chemical = Sheets("Chemicals").Cells.Find(What:=lstChemicalDatabase.Text, LookIn:=xlFormulas, _ LookAt:=1, SearchDirection:=xlNext, MatchCase:=False).Offset(0, 0).Address With Sheets("Chemicals").Range(Chemical) TextBoxName.Text = .Offset(0, 0) TextBoxCAS.Text = .Offset(0, 1) TextBoxMW.Text = .Offset(0, 2) TextBoxDensity.Text = .Offset(0, 3) TextBoxConc.Value = .Offset(0, 4) TextBoxMaterial.Text =...

Digits in textbox's
Hi all just wondering how I can get someone only to type number in a certain textbox? Thanks in advance Greg Is this a TextBox on a UserForm? Somewhat crude, but try the following: Private Sub TextBox1_Change() If Not IsNumeric(TextBox1.Text) Then _ SendKeys "{BACKSPACE}" End Sub -- Vasant "Greg B" <laptopgb@ihug.com.au> wrote in message news:dff3gt$uti$1@lust.ihug.co.nz... > Hi all just wondering how I can get someone only to type number in a > certain > textbox? > > Thanks in advance > > Greg > > Thank you for ...

display / print 0's in pivot table cells
have a pivot table with blank cells. people would like to have 0's in the cells. doable? Select a cell in the pivot table On the PivotTable toolbar, choose PivotTable>Table Options Check the box 'For empty cells, show' In the text box, type a zero Click OK Mark wrote: > have a pivot table with blank cells. people would like to have 0's in the > cells. > doable? -- Debra Dalgleish Excel FAQ, Tips & Book List http://www.contextures.com/tiptech.html ...

To get fomula to display a Zero
I Have a foumula in G35 that takes the sum of 2 other cells(G32).This formula "=SUM(G32,-69.4*113/119)" in G35 generates a number when the sum in the cell G32 is 0, which is probably what I'm telling it to do. But in reality I would like G35 to display a "0" (Doing the formula on my calculator yields -65.9008 which is what excell G35 does.) I have tried using a fix that was supplied to me earlier. Can someone Help please? -- Geo =IF(G32=0,0,SUM(G32,-69.4*113/119) -- HTH RP (remove nothere from the email address if mailing direct) "Geo" <Geo@dis...

Outlook "unable to display the folder....."
Hi...BIG problem... I get the following error message: "Unable to display the folder. Another application closed unexpectedly while using your Personal Folders file C:\DocumentsandSettings\JanetJuneau\LocalSettings\ApplicationData\Microsoft\Outlook\outlook.ost To prevent potential damage to your personal folders file, it will not be available until you close all applications currently using it" HELP HELP HELP!!!!! Tried restarting your computer already? Which version of Outlook are you using? Which applications do you have installed which integrate with Outlook...