+ Reply to Thread
Results 1 to 6 of 6

Copy cells from column to userform text boxes by selection

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    05-12-2009
    Location
    Hendersonville, TN
    MS-Off Ver
    Excel 2010
    Posts
    113

    Copy cells from column to userform text boxes by selection

    Hello all,

    I have a worksheet with some data I would like to transfer to a userform. The form has a combobox that a testing modality can be selected. I want to know how to get the remainder of the userform text boxes to populate with the proper column information from the worksheet. Thank you for all your help.


    Patrick
    Attached Files Attached Files

  2. #2
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: Copy cells from column to userform text boxes by selection

    Private Sub ComboBox1_Change()
    Dim WS As Worksheet
    Dim Rng As Range
    Dim A As Long
    Dim Temp As String
    
    Set WS = Worksheets("Sheet1")
    
    With WS.Range("C1:G1")
        Set Rng = .Find(Me.ComboBox1, , xlValues)
        If Not Rng Is Nothing Then
            For A = 1 To 6
                Me.Controls("TextBox" & A) = .Cells(A + 1, Rng.Column)
            Next
            For A = 8 To 12
                Temp = Temp & .Cells(A, Rng.Column) & vbCr
            Next
            Me.TextBox7.MultiLine = True
            Me.TextBox7 = Temp
        End If
    End With
    End Sub
    David
    (*) Reputation points appreciated.

  3. #3
    Forum Contributor
    Join Date
    05-12-2009
    Location
    Hendersonville, TN
    MS-Off Ver
    Excel 2010
    Posts
    113

    Re: Copy cells from column to userform text boxes by selection

    Thank you for the code David. I tried it out and it works, sort of. Not sure why, but it seems to index 2 columns to the right and pulls in the information from the wrong column. Example: I make my selection in the combobox for what should pull, column C. Instead of column C, I get info from coulumn E. I haven't seen anywhere in the code that jumps out and says hey go 2 to the right. My data range is in columns C thru G at this time. Any ideas on what I should do to correct this?

    Thanks,
    Patrick

  4. #4
    Forum Contributor
    Join Date
    05-12-2009
    Location
    Hendersonville, TN
    MS-Off Ver
    Excel 2010
    Posts
    113

    Re: Copy cells from column to userform text boxes by selection

    Thank you for the code David. I tried it out and it works, sort of. Not sure why, but it seems to index 2 columns to the right and pulls in the information from the wrong column. Example: I make my selection in the combobox for what should pull, column C. Instead of column C, I get info from coulumn E. I haven't seen anywhere in the code that jumps out and says hey go 2 to the right. My data range is in columns C thru G at this time. Any ideas on what I should do to correct this?

    Thanks,
    Patrick

  5. #5
    Forum Contributor
    Join Date
    05-12-2009
    Location
    Hendersonville, TN
    MS-Off Ver
    Excel 2010
    Posts
    113

    Re: Copy cells from column to userform text boxes by selection

    Spent some time working with the code. I made a small edit and it seems to have fixed the issue. I changed the range from C1:G1 to A1:G1. Here is the edited code:
    Private Sub ComboBox1_Change()
    Dim WS As Worksheet
    Dim Rng As Range
    Dim A As Long
    Dim Temp As String
    
    Set WS = Worksheets("Sheet1")
    
    With WS.Range("A1:G1")
        Set Rng = .Find(Me.ComboBox1, , xlValues)
        If Not Rng Is Nothing Then
            For A = 1 To 6
                Me.Controls("TextBox" & A) = .Cells(A + 1, Rng.Column)
            Next
            For A = 8 To 12
                Temp = Temp & .Cells(A, Rng.Column) & vbCr
            Next
            Me.TextBox7.MultiLine = True
            Me.TextBox7 = Temp
        End If
    End With
    End Sub

  6. #6
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: Copy cells from column to userform text boxes by selection

    Glad you got it sorted. I was on the road today, hence my silence. Great work!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 4
    Last Post: 02-20-2014, 02:24 PM
  2. [SOLVED] Clear all text boxes-combo boxes in a userform.
    By MariaPap in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-31-2014, 11:16 AM
  3. [SOLVED] Help with code for userform text boxes, combo boxes and excel
    By innerise in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-20-2014, 09:07 AM
  4. Populate Text Boxes based on Combo Box Selection
    By Sasha28 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-14-2012, 06:32 PM
  5. Multiple text boxes selection
    By Rafisahb in forum Excel Formulas & Functions
    Replies: 26
    Last Post: 09-06-2005, 03:05 PM

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