Search code examples
excelvba

Determine which pages textbox has text on multipage




Is it possible to determine on which pages textbox has any value?
and getting the name of the non-empty textbox tab.

Setup:
On Page1 TextBox1, On Page2 TextBox2.
If TextBox2 has value init I need to get the name of the Page.
Thanks in advance!

Multipage

What I've tried so far is to get values from specific textboxes.

Dim z As Integer
For z = 5 To 11
    If step_0.Controls("TextBox" & z).Value <> "" Then
        sValue = sValue & step_0.Controls("TextBox" & z).Value & vbCrLf
    End If
Next

I'd like to do it with the tab names, it's a tricky one cause textboxes not linked to tabs.


Solution

  • So after thinking a little bit I found this solution.
    This comes handy if you want to work with multipage captions combined with text boxes.
    Code:

    a = ""
    Dim r As Integer
    For r = 5 To 12
    'according to count of textboxes should be 1 to whatever
        If UserForm1.Controls("TextBox" & r).Value <> "" Then
        a = a & " " & UserForm1.MultiPage1.Pages(r - 5).Caption
    'since the first page index is 0, subtract the integer. It only works if they arranged like this:
    'page0-tbox1,page1-tbox2 page_n-tbox_n+1....
    'a= creates a list with the captions of pages which has fulfilled textboxes.
        End If
    Next