+ Reply to Thread
Results 1 to 9 of 9

Thread: Copy List of Userform Data to Worksheet

  1. #1
    Registered User
    Join Date
    05-23-2011
    Location
    New York, NY
    MS-Off Ver
    Excel 2003
    Posts
    60

    Copy List of Userform Data to Worksheet

    Hello,

    Is there an easier way of copying a list of various userform txtbox values to one column in excel? There are many more than what I list below, so aggregating the whole process would be more efficient for me.

    Thanks

    Set ws = ThisWorkbook.Worksheets("saveclose")
    
    ws.Cells(1, 2).Value = Me.txtNAME.Value
    ws.Cells(2, 2).Value = Me.txtPHONE.Value
    ws.Cells(3, 2).Value = Me.txtDATE.Value
    ws.Cells(4, 2).Value = Me.txtMNGR.Value
    ws.Cells(5, 2).Value = Me.cmboSTRAT.Value
    ws.Cells(6, 2).Value = Me.txtFIRM.Value
    ws.Cells(7, 2).Value = Me.txtSTRASSET.Value
    Last edited by gsurge; 08-22-2011 at 10:15 AM.

  2. #2
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,640

    Re: Copy List of Userform Data to Worksheet

    That code will overwrite previous entries. Is this what you want?
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

  3. #3
    Registered User
    Join Date
    05-23-2011
    Location
    New York, NY
    MS-Off Ver
    Excel 2003
    Posts
    60

    Re: Copy List of Userform Data to Worksheet

    Yes, I would like to start in the first cell of column "B" each time the code runs.

  4. #4
    Forum Guru jaslake's Avatar
    Join Date
    02-21-2009
    Location
    mineral city, ohio
    MS-Off Ver
    Excel 2007; Excel 2000
    Posts
    4,004

    Re: Copy List of Userform Data to Worksheet

    Hi gsurge

    Attached is an example of how you can do as you describe. It requires careful naming and sequencing of your TextBox Controls. You'll need to rename your TextBox Controls back to "TextBox1, TextBox2, etc".

    Try it...if you like it...use it...else lose it.
    Attached Files Attached Files
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  5. #5
    Registered User
    Join Date
    05-23-2011
    Location
    New York, NY
    MS-Off Ver
    Excel 2003
    Posts
    60

    Re: Copy List of Userform Data to Worksheet

    Thank you for the effort, but unfortunately that is a bit too restrictive for me, as re-naming is too difficult this late in the process.


    Is there no way to simply create a list of all the listbox names and export them together?

  6. #6
    Valued Forum Contributor Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    2010
    Posts
    952

    Re: Copy List of Userform Data to Worksheet

    One can get a list of all textbox controls and then you can get the names or values as needed. For your example though, I don't know how that would help as you have a combobox in the list.

    If you set the value to some specific cell, you could just set the ControlSource property.

  7. #7
    Registered User
    Join Date
    05-23-2011
    Location
    New York, NY
    MS-Off Ver
    Excel 2003
    Posts
    60

    Re: Copy List of Userform Data to Worksheet

    I actually removed the combo from the list, so it is entirely made up of listboxes.

    Can you please provide an example of what you are referring to?

  8. #8
    Valued Forum Contributor Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    2010
    Posts
    952

    Re: Copy List of Userform Data to Worksheet

    I first posted how to do this method at: http://www.mrexcel.com/forum/showthread.php?p=1626849

    In a Module:
    Option Explicit
    
    Public cCB() As Control, cTB() As Control
    In the Userform:
    'Public cCB() As Control, cTB() As Control 'In a Module
    Private Sub UserForm_Initialize()
      FillControlArrays
    End Sub
    
    Private Sub FillControlArrays()
      Dim iCB As Integer, iTB As Integer, c As Control
    
      For Each c In Me.Controls
        Select Case TypeName(c)
          Case "TextBox"
            iTB = iTB + 1
            ReDim Preserve cTB(1 To iTB)
            Set cTB(iTB) = c
           Case "ComboBox"
            iCB = iCB + 1
            ReDim Preserve cCB(1 To iCB)
            Set cCB(iCB) = c
          End Select
        Next c
    End Sub
    You can then use standard methods to iterate the control arrays to get or put what you need. In your case, you would iterate cTB().

  9. #9
    Registered User
    Join Date
    05-23-2011
    Location
    New York, NY
    MS-Off Ver
    Excel 2003
    Posts
    60

    Re: Copy List of Userform Data to Worksheet

    That is great. Thank you all for your input

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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.2.0