If Then Else statements resulting in multiple errors

basicallyawesome

New Member
Joined
Jul 10, 2018
Messages
29
Office Version
  1. 365
I am relatively new to VBA, which I've been using to solve basic problems and automate reasonably complex tasks for my workplace. My most complex one (so far!) is actually two documents: a data source housed in Excel and then the merge letter in Word. Rigging the Word document to do what I want it to was fairly easy, but I seem to have hit a wall with Excel.

While I understand IF statements as they pertain to formulas, I have yet to write one that actually works in VBA, and I think I require 2. Unfortunately I have no "real world" example because my work is protected under privacy legislation and confidentiality agreements, but the first one is basically:

If [Combobox].value = "Blurb2" then
Show.[B2Userform]
Elseif [Combobox].value = "Blurb3" then Show.[B3Userform]
...and so on, through roughly 18 "blurbs". Per various posts on here and other Excel/VBA forums, the code looks right but when I go to run it, I either get End If Without Block If or Else If Without If errors. I am completely lost on what I'm doing wrong, I've read basically everything and I still can't fix my problem.

The second one I need is more complex, and this didn't bring up any errors but also didn't do what I needed it to. It did... nothing.
If [Combobox].value = "Blurb2" then
[MainUserform].Hide
Elseif [Combobox].value = "Blurb3" then [MainUserform].Hide
...and again so on through the same roughly 18 "blurbs". The more I think about this one, the more I wonder if I truly need it. Will having the main user form in the background of the additional info/blurb userforms use a lot of memory overall?

If it makes a difference, both are supposed to be triggered by command buttons.

Thank you so much for any help you can provide! I've been reading this forum for a while now and have found it an invaluable resource.
 
Thank you so much to both of you. I did wind up going with the set case solution so that if the value of the blurb is [blurb2], it takes you to the corresponding page in the multi page form to fill in the additional information. I then went on to use the same set up to do a bunch of other things in other projects that had stalled at If. Thanks again!
 
Upvote 0

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Glad we were able to help you.
Come back here to Mr. Excel next time you need additional assistance.

So you decided on the Multipage solution I assume.
Should be a lot easier then using 18 Userforms.
I love Userforms and Multipages
I Sort out all types of things using Multipages.
One page tab for this and another for that.
For standard buttons that you need just place them outside the Multipage but still on the Userform.
Like a close button for closing your userform.
 
Upvote 0
Did you know you can make your userform very colorful?
1.In edit mode click on the userform.
2.In the properties window click on Back Color click on palette and choose the color you like


To color your Multipage

1.Put a Image control overtop of the multipage
2.Click on the image
3. In the properties window click on BackColor
4. Choose the palette and select the color you like
5. The image will cover all of the Multipage except for the tabs. Tabs cannot be colored
6. Right click on image and choose SendBackwards
7. Presto you have a colorful Multipage
8. Do all this before you put all your controls on the userform otherwise you may have to use send backwards several times.

You will have to do this on all your Multipage tabs. If you want them all colored.
A lot more nice looking then the standard colors
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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