+ Reply to Thread
Results 1 to 11 of 11

Select & edit items in a listbox in VBA

Hybrid View

  1. #1
    Registered User
    Join Date
    07-07-2004
    Posts
    35
    Hi Ardus

    This is what my code looks like:
    
    Private Sub ListBox1_Click()
    txtRank.Value = ListBox1.Value
    End Sub
    
    Private Sub txtRank_Change()
    Dim rCell As Range
        With ListBox1
            Set rCell = Range(.RowSource).Offset(.ListIndex).Resize(1)
            rCell.Value = txtRank.Value
        End With
    End Sub
    
    
    Private Sub UserForm_Initialize()
    
    ListBox1.ColumnCount = 1
    ListBox1.RowSource = "SourceRank" 'I set it so that when the form is loaded the list in SourceRank(Defined name - Col A:A) is displayed in the listbox, I dont know if this might be the problem or not?
    
    End Sub
    Kind Regards

  2. #2
    Ardus Petus
    Guest

    Re: Select & edit items in a listbox in VBA

    That was because you define SourceRank as $A:$A
    I don't think it's a good idea, since your ListBox shows 65536 rows!

    Anyway, this fixes the bug:

    Private Sub txtRank_Change()
    Dim rCell As Range
    With ListBox1
    Set rCell = Range(.RowSource).Resize(1).Offset(.ListIndex)
    rCell.Value = txtRank.Value
    End With
    End Sub

    HTH
    --
    AP

    "poppy" <poppy.27ou3z_1147426203.0779@excelforum-nospam.com> a écrit dans le
    message de news: poppy.27ou3z_1147426203.0779@excelforum-nospam.com...
    >
    > Hi Ardus
    >
    > This is what my code looks like:
    >
    > Code:
    > --------------------
    >
    >
    > Private Sub ListBox1_Click()
    > txtRank.Value = ListBox1.Value
    > End Sub
    >
    > Private Sub txtRank_Change()
    > Dim rCell As Range
    > With ListBox1
    > Set rCell = Range(.RowSource).Offset(.ListIndex).Resize(1)
    > rCell.Value = txtRank.Value
    > End With
    > End Sub
    >
    >
    > Private Sub UserForm_Initialize()
    >
    > ListBox1.ColumnCount = 1
    > ListBox1.RowSource = "SourceRank" 'I set it so that when the form is
    > loaded the list in SourceRank(Defined name - Col A:A) is displayed in the
    > listbox, I dont know if this might be the problem or not?
    >
    > End Sub
    >
    > --------------------
    >
    >
    > Kind Regards
    >
    >
    > --
    > poppy
    > ------------------------------------------------------------------------
    > poppy's Profile:
    > http://www.excelforum.com/member.php...o&userid=11453
    > View this thread: http://www.excelforum.com/showthread...hreadid=540220
    >




  3. #3
    Registered User
    Join Date
    07-07-2004
    Posts
    35

    Talking

    Hi Ardus

    Thank you. My listbox works perfectly now. I really appreciate all your help and patience.

    Kind Regards

  4. #4
    Registered User
    Join Date
    12-14-2012
    Location
    USA
    MS-Off Ver
    Excel 2011
    Posts
    2

    Re: Select & edit items in a listbox in VBA

    So I'm trying this same code & it works for me, all the way to executing the changes from textbox back into the cell. Ay ideas? BTW, I'm on Excel 2011 for Mac & there were a few changes needed to keep the code working to that point. Here's my code:


    Private Sub ListBox1_Click()
    TextBox1.Value = ListBox1.Value
    End Sub
    Private Sub Texbox1_Change()
    Dim rCell As Range
    With ListBox1
    Set rCell = Range(.List).Resize(1).Offset(.ListIndex)
    rCell.Value = TextBox1.Value
    End With
    End Sub

    Private Sub UserForm_Initialize()
     ListBox1.ColumnCount = 1
     ListBox1.List = [BHrange].Value
    End Sub
    Last edited by arlu1201; 02-01-2013 at 01:12 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1