Results 1 to 3 of 3

Thread: How To Save Data To SpreadSheet From Only TextBoxes In All MultiPages Of A User Form

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,401
    Rep Power
    10
    Happy new year szchris384. And welcome to ExcelFox

    If you use a for each loop, the loop order will take it by tab order. However, to keep things more in control, it would be better to give specific names to your controls. Like txtMP1Data1, txtMP1Data2, txtMP1Data3, txtMP2Data1, txtMP2Data2, txtMP2Data3, txtMP3Data1 etc

    That way, you can do a loop like this.

    Code:
    Sub GetDataFromAllTextBoxesByName()
    
        Dim lngMultiPages   As Long
        Dim lngCount        As Long
        Dim lngCounter      As Long
        Dim lngColIndex     As Long
        For lngMultiPages = 0 To Me.MultiPage1.Pages.Count - 1
            For lngCount = 0 To Me.MultiPage1.Pages(lngMultiPages).Controls.Count - 1
                If TypeName(Me.MultiPage1.Pages(lngMultiPages).Controls(lngCount)) = "TextBox" Then
                    lngCounter = lngCounter + 1
                End If
            Next lngCount
            For lngCounter = 0 To lngCounter - 1
                lngColIndex = lngColIndex + 1
                Cells(3, lngColIndex).Value = Me.MultiPage1.Pages(lngMultiPages).Controls("txtMP" & lngMultiPages & "Data" & lngCounter).Text
            Next lngCounter
            lngCounter = 0
        Next lngMultiPages
        
    End Sub
    The other way of course is to go with the tab order

    Code:
    Sub GetDataFromAllTextBoxesByTabOrder()
    
        Dim lngMultiPages   As Long
        Dim lngCount        As Long
        Dim lngCounter      As Long
        
        For lngMultiPages = 0 To Me.MultiPage1.Pages.Count - 1
            For lngCount = 0 To Me.MultiPage1.Pages(lngMultiPages).Controls.Count - 1
                If TypeName(Me.MultiPage1.Pages(lngMultiPages).Controls(lngCount)) = "TextBox" Then
                    lngCounter = lngCounter + 1
                    Cells(2, lngCounter).Value = Me.MultiPage1.Pages(lngMultiPages).Controls(lngCount).Text
                End If
            Next lngCount
        Next lngMultiPages
        
    End Sub
    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

Similar Threads

  1. Inserting Image In VBA User Form Caption
    By littleiitin in forum Download Center
    Replies: 3
    Last Post: 02-22-2021, 03:07 PM
  2. Replies: 11
    Last Post: 10-13-2013, 10:53 PM
  3. Sending Data From User Form To First Empty Row Of Sheets
    By paul_pearson in forum Excel Help
    Replies: 21
    Last Post: 08-14-2013, 11:04 PM
  4. Populate data in form
    By Ryan_Bernal in forum Excel Help
    Replies: 4
    Last Post: 02-01-2013, 10:18 AM
  5. Adding A Menu Bar To A User Form
    By Rasm in forum Excel Help
    Replies: 14
    Last Post: 05-05-2011, 04:05 AM

Tags for this Thread

Posting Permissions

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