Search code examples
excelvbauserformmultipage

If Userform Multipage Sheet Is active, then execute function


I'm trying to have a Userform pull the name of the Active multipage sheet to a specific column in my workbook. There are 4 pages in the userform which contain option buttons that feed into the workbook. The option button data already submits correctly.

I need the name of the page so I can categorize the option button results. Here are some of the ways I've tried.

  1. If Page1.Page.Value = 0 Then
       x.Cells(nextRow, 4) = "Category 1"
    End IF
    
  2. If Page1.Value = True Then
       x.Cells(nextRow, 4) = "Category 1"
    End IF
    
  3. If Page1.Value = True Then
       x.Cells(nextRow, 4) = Me.Page1.Caption
    End IF
    

Any suggestions?


Solution

  • Consider using the caption of SelectedItem property to get the name of the active page:

    If MultiPage1.SelectedItem.Caption = "myPageName" Then
       x.Cells(nextRow, 4) = "needed value"
    End IF
    

    Or succinctly if you want cell value to point to current multipage name:

    x.Cells(nextRow, 4) = MultiPage1.SelectedItem.Caption
    

    See this informative tutorial on the MultiPages object.