Excel/UserForm

Advertisement


Question
QUESTION: Hi Tom

Can you help?

i have a worksheet labeled Customer and a userform
named Address

in cell A13 i have a list box for yes/no

if yes is chosen in A13 I would like the Userform
named Address to open, but am lost for the code
for vba?

Thank you ahead of time if its possible

Tony

ANSWER: Tony

First, I assume you have a dropdown box produced by using the LIST option in Data validation.  Otherwise, if it is a listbox, then it may be above cell A13 and you would have to tie code to the listbox's event - I will assume as I said that it is a dropdown box in the cell from Data validation.

right click on the sheet tab where you want this functionality (worksheet Customer) and paste in code like this:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$13" Then
 If LCase(Target.Value) = "yes" Then
   Userform1.Show
 End If
End If
End Sub

replace userform1  with the objectname of your userform.  So if it is Address then

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$13" Then
 If LCase(Target.Value) = "yes" Then
   Address.Show
 End If
End If
End Sub



--
Regards,
Tom Ogilvy




---------- FOLLOW-UP ----------

QUESTION: Tom

Thanks,

yes a drop down was correct.

it worked great!!

is there a way to have more than one on the same sheet?

i have two on this page with different cells and different
userforms, but when i tried to copy that code and pasted it using a different cell it gave me an error.  

Is it possible?

Tony

Answer
Tony,

In the same routine you just set it up to act with different actions for different cells triggering the event.

Private Sub Worksheet_Change(ByVal Target As Range)
Select Case Target.Address
 Case "$A$13"
   If LCase(Target.Value) = "yes" Then
      Address.Show
   End If
 Case "$A$15"
   If LCase(Target.Value) = "yes" Then
     Userform2.Show
   End If
 Case "$A$17"
   If LCase(Target.Value) = "yes" Then
     Userform3.Show
   End If
End Select
End Sub

--
Regards,
Tom Ogilvy

About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here

Excel

All Answers


Answers by Expert:


Ask Experts

Volunteer


Tom Ogilvy

Expertise

Selected as an Excel MVP by Microsoft since 1999. Answering Excel questions in Allexperts since its inception in 2001. Able to answer questions on almost all aspects of Excel's internal capabilities. If seeking a VBA solution, please specify that in your question itself so I give you the answer you want. [Excel has weak protection - if you are distributing an application, I don't answer questions on how to protect your project from your users.]

Experience

Extensive experience.

Education/Credentials
Master of Science (MS) degree Operations Research (ORSA)

Awards and Honors
Microsoft MVP in Excel.

©2016 About.com. All rights reserved.