Opening a Userform based on Vlookup Variable

lnmpurdue15

New Member
Joined
May 17, 2018
Messages
3
Hi Everyone.

I need some assistance and I am hoping this group can help.

Overview: I am creating an interactive document when first opened, a user will see a userform with a variety of themes with checkboxes. For the themes they want, they select a checkbox and then depending on the checkbox(es) selected, the VBA code will open the next userform which allows them to select applicable questions.

I have created all the userforms and a command button on the main menu. What I want is when the command button is clicked, the VBA code will identify which secondary userform it needs to open next (I have 16 different userforms) and open it for the user to select questions; however, I am unable to get the secondary userform to open. If I hard code the userform name.show it will open but when I try to open it from a variable string VBA errors out with a compile error, invalid qualifier.

Here is the code I have developed so far:

Code:
 Private Sub CommandButton2_Click()

 Dim Ret As String

 Unload Main_Menu

 Sheets("Themes").Activate

 range("A3:A22").Select
 Selection.TextToColumns Destination:=range("A3"), DataType:=xlDelimited, _ 'This section is converting checkbox values (True/False) from the main userform (i.e. the themes) into text for the vlookup to work.
 TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
 Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
 :=Array(1, 2), TrailingMinusNumbers:=True

 Ret = Application.VLookup("True", Sheets("Themes").range("$A$3:$C$20"), 3, False) ' the 3rd column over has the associated userform name that I am trying to open

 Ret.Show
I know the first part of the code is working as I want it. If I do a message box and the Ret value, I get the appropriate userform name. So what I don't know is what I need to do to get the identified variable to open the next userform.

Is there a simple way without having to list all the userform options? I tried a select case and that didn't want to work either.

Any suggestions?
 
Last edited by a moderator:

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Welcome to the forum.

Try this:

Code:
Userforms.Add(Ret).Show
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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