Results 1 to 5 of 5

Thread: Change listbox value

  1. #1
    Junior Member
    Join Date
    Oct 2012
    Posts
    26
    Rep Power
    0

    Change listbox value

    Hello,

    I have created a sheet with a rowsource from A1:L19 in sheet1

    What i want to do is change the value's in a userform. I have an example of how i like to see it.

    http://www.excelforum.com/excel-prog...x-records.html

    But in that case i need to create for every cell a separate text box. Is there a easier way to manage/change this? I only need to have the buttons edit and change. How can i manage this?
    See attached file.Change listbox.xlsm

  2. #2
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10
    can you please post the link again as it seems broken.
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

  3. #3
    Junior Member
    Join Date
    Oct 2012
    Posts
    26
    Rep Power
    0
    Quote Originally Posted by Admin View Post
    can you please post the link again as it seems broken.
    Edit Add Delete Listbox Records

  4. #4
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,402
    Rep Power
    10
    This should help. I've added textboxes to a second userform during run time when you click on one row in the first userform.

    Here's the code for reference

    Code:
    Public var As Variant
    Dim rng As Range
    Private Sub ListBox1_Click()
    
        UserForm2.Show 0
        
    End Sub
    
    Private Sub UserForm_Initialize()
    
        With ListBox1
            Set rng = Worksheets(Replace(Split(.RowSource, "!")(0), "'", "")).Range(Split(.RowSource, "!")(1))
    'If your row source doesn't have reference to a sheet, but only to a range, just use Set rng = Range(RowSource)
        var = rng
            .RowSource = ""
            .List = var
        End With
        
    End Sub
    
    Private Sub UserForm_Terminate()
    
        rng.Value = var
        
    End Sub
    Code:
    Dim txtSampleTextBox() As MSForms.TextBox
    Private Sub UserForm_Initialize()
        
        Dim lng As Long
        Dim obj As MSForms.TextBox
        lng = UserForm1.ListBox1.ColumnCount
        ReDim Preserve txtSampleTextBox(1 To lng)
        
        For lng = 1 To lng
            Set txtSampleTextBox(lng) = Controls.Add("Forms.TextBox.1", "txtSampleTextBox" & lng)
            With txtSampleTextBox(lng)
                .Left = (lng - 1) * .Width + 5
                .Text = UserForm1.ListBox1.List(UserForm1.ListBox1.ListIndex, lng - 1)
            End With
        Next lng
        Me.Width = (lng - 1) * (txtSampleTextBox(lng - 1).Width + 1)
    
    End Sub
    
    Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    
        Dim lng As Long
        With UserForm1.ListBox1
            For lng = 1 To Me.Controls.Count
                .List(.ListIndex, lng - 1) = Controls("txtSampleTextBox" & lng).Text
            Next lng
            UserForm1.var = .List
        End With
        
    End Sub
    Attached Files Attached Files
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  5. #5
    Junior Member
    Join Date
    Oct 2012
    Posts
    26
    Rep Power
    0
    How can i add this to a multipage? in one userform i have a multipage with 5 tabs. Each tab has it's own listbox connected to a sheet. And is it also possible to make the changescreen fixed under the listbox directly? I only want to show a textbox when there is a value in the sheet
    Last edited by Tony; 12-04-2012 at 09:02 PM.

Similar Threads

  1. Maximum columns in a ListBox
    By Rasm in forum Excel Help
    Replies: 7
    Last Post: 05-04-2020, 12:44 PM
  2. How To Create DropDown ListBox In Excel
    By lokvan in forum Excel Help
    Replies: 3
    Last Post: 12-23-2014, 04:43 PM
  3. Replies: 8
    Last Post: 04-16-2013, 02:04 PM
  4. Change Display Range Based On Change of Dropdown Values
    By rich_cirillo in forum Excel Help
    Replies: 2
    Last Post: 03-29-2013, 04:58 AM
  5. Using ListView - a Listbox on steroids
    By Rasm in forum Download Center
    Replies: 3
    Last Post: 04-09-2011, 03:34 AM

Posting Permissions

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