How do you differentiate userforms in the same worksheet?

rizzo93

Active Member
Joined
Jan 22, 2015
Messages
299
Office Version
  1. 365
I need help understanding how to have userforms on several worksheets. It's the coding I'm focused on.

On one sheet I've created a button assigned to a macro that pops up a multipage window with text. Now that I've started creating another userform (StartHelp) for a different worksheet, I'm running into conflicts.

The little coding experience I have tells me that I need to differentiate each form (and others that have yet to be created). The code for the sheet that works is:
Private Sub CommandButton1_Click()
Unload Me

End Sub
Private Sub Label4_Click()
End Sub
Private Sub UserForm_Initialize()
Me.MultiPage1.Value = iPage
End Sub

The module for the sheet that works is:
Option Explicit
Public iPage As Integer
Sub help0()
iPage = 0
CharterHelp.Show
End Sub

How should I proceed, please?
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Userforms aren't associated with specific sheets, or workbooks really for that matter.

What problems/conflicts are you having?
 
Upvote 0
Thanks for replying, Norie. That's good to know.

I don't understand how to specify which form I want to show on each sheet when I click a button. I know macros are relevant, but I'm a little fuzzy on how to associate those macros.

For example, the code below references CharterHelp and the macro help0 (correct me if I'm mistaken please).

Option Explicit
Public iPage As Integer
Sub help0()
iPage = 0
CharterHelp.Show
End Sub

But if my understanding is correct, I think I need to add the other userform(s) like so:

Public iPage As Integer
Sub help0()
iPage = 0
StartHelp.Show
End Sub


However, I see both Sub help and iPage referencing the same 0.

Am I heading in the right direction?
 
Upvote 0
Do you have all this code in one module?

If you do then you'll get an 'Ambiguous name detected' error.

What are you going to do with iPage?
 
Last edited:
Upvote 0
No, I was just posting the code. I'm not familiar enough with iPage to know the extent of how it can/should be properly used. It was just the term I used according to an example I was following.

But as to what I'm going to do with it, I just have it set to show the CharterHelp userform.
 
Upvote 0
As far as I can see iPage has absolutely nothing to do with showing either userform.

You should be able to use this code like this to show them.
Code:
Option Explicit

Sub ShowCharterHelp()
    CharterHelp.Show
End Sub

Sub ShowStartHelp()
    StartHelp.Show
End Sub

If you had these 2 subs in a standard module (Insert>Module) then you could assign them to Forms buttons on the relevant sheets to show the relevant userform.

PS You mention a multipage? Was iPage going to be used to set which page was on display when the userform(s) opened?
 
Upvote 0
I now understand what you meant about the iPage.

Originally, I had multiple buttons on a worksheet that would popup the same window for all of the buttons, but would land the appropriate page in that window based on the context of the button's location.

Example:
One button was for "Statement", another button was for "Objectives", another was "Goals." Each of these buttons was going to open the same window, but land on the page with the content that was associated with the button they clicked on.

I've since decided against that path and now only using one button on each worksheet. When you click on that button it will launch a multipage window specific to that worksheet like before, but I no longer care about landing on a particular page of that window; users will just have to scroll through them, if need be.

I'm sorry for the confusion. Hopefully, I've clarified it for you and made things a bit simpler. (I hope. :) )
 
Upvote 0
Kind of clarified things, but I assume by 'window' you mean 'userform'?:)
 
Upvote 0

Forum statistics

Threads
1,214,431
Messages
6,119,457
Members
448,898
Latest member
drewmorgan128

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top