Search TeachExcel.com
TeachExcel.com
TE
Teach Excel MS Office Tutorials Excel Consulting Services Excel Forum
Excel Video Tutorials Excel Tips Free Excel Macros Excel Help Resources Contact TeachExcel
Video Tutorials
  • Free Macros
  • Excel Help Directory
  • Excel 2007 Resources
  • Keyboard Shortcuts
  • Excel Forum
  • Contact/About

Macros
Excel Tutorials For Macros

Add a Drop Down Menu to a Cell in Excel - Data Validation Macro


Bookmark and Share

Add a drop down menu or list to a cell in Excel with this free Excel macro. This is a great little macro that allows you to automatically add a drop down menu to any cell within a worksheet in Excel. This is part of the data validation features in Excel and this macro, since it is self-contained, is very easy to add to any other macro you may be using.

Both macros listed below add drop down menus or lists to cells in Excel; but, but the first one will add a drop down menu to a specific cell that you hard code into the macro whereas the second macro adds a drop down menu into any cell that has been selected before the macro is run.

To use the macros below, simply replace A1 (that appears in Range("A1").Validation) in the first macro with the cell reference of the cell in which you want the drop down menu to appear. Then, in both macros replace =$D$1:$D$3 with the range of the list which will populate or fill the drop down menu; if you are using a named range, input the name in place of that range reference.
Where to install the macro:  Module

Excel Data Validation Macro that Adds a Drop Down Menu to a Specific Cell in Excel

Sub Add_Drop_Down_Menu_Cell()

With Range("A1").Validation
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, _
Formula1:="=$D$1:$D$3"
.IgnoreBlank = True
.InCellDropdown = True
End With

End Sub


Excel Data Validation Macro that Adds a Drop Down Menu to a Selected Cell in Excel

Sub Add_Drop_Down_Menu_Selection()

With Selection.Validation
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, _
Formula1:="=$D$1:$D$3"
.IgnoreBlank = True
.InCellDropdown = True
End With

End Sub


Bookmark and Share


How to Install the Macro
  1. Select and copy the text from within the grey box above.

  2. Open the Microsoft Excel file in which you would like the Macro to function.

  3. Press "Alt + F11" - This will open the Visual Basic Editor - Works for all Excel Versions.  Or For other ways to get there, Click Here.

      For Excel Versions Prior to Excel 2007
      Go to Tools > Macros > Visual Basic Editor

      For Excel 2007
      Go to Office Button > Excel Options > Popular > Click Show Developer tab in the Ribbon. Then go to the Developer tab on the ribbon menu and on the far left Click Visual Basic

  4. On the new window that opens up, go to the left side where the vertical pane is located. Locate your Excel file; it will be called VBAProject (YOUR FILE'S NAME HERE) and click this.

  5. If the Macro goes in a Module, Click Here, otherwise continue to Step 8.

    1. Go to the menu at the top of the window and click Insert > Module
    2. Another window should have opened within the Visual Basic Editor's window. Within this new window, paste the macro code. Make sure to paste the code underneath the last line of anything else that is in the window.
    3. Go to Step 8.

  6. If the Macro goes in the Workbook or ThisWorkbook, Click Here, otherwise continue to Step 8.

    1. Directly underneath your excel file called VBAProject(your file's name here), click the Microsoft Excel Objects folder icon to open that drop-down list.
    2. Then, at the bottom of the list that appears, double-click the ThisWorkbook text.
    3. A new window inside the Visual Basic Editor's window will appear. In this new window, paste the code for the macro. Make sure to paste this code underneath the last line of any other code which is already in the window.
    4. Go to Step 8.

  7. If the Macro goes in the Worksheet Code, Click Here, otherwise continue to Step 8.

    1. Directly underneath your excel file called VBAProject(your file's name here), click the Microsoft Excel Objects folder icon to open that drop-down list.
    2. Within the list that appears you will see every worksheet that is in that excel file. They will be listed as such: Sheet1(NAME OF SHEET HERE) and under that will be Sheet2(NAME OF SHEET HERE). Select the sheet in which you want the macro to run and double-click that sheet.
    3. A new window inside the Visual Basic Editor's window will appear. In this new window, paste the code for the macro. Make sure to paste this code underneath the last line of any other code which is already in the window.
    4. Repeat steps b and c for every sheet you want the macro to work in. Putting the macro in one sheet will not enable it for any other sheets in the workbook.
    5. Go to Step 8.

  8. Close the Microsoft Visual Basic Editor window and save the Excel file. When you close the Visual Basic Editor window, the regular Excel window will not close.

  9. You are now ready to run the macro.



Similar Helpful Excel Resources

How To Prevent Clearing A Cell Containing A Drop Down Menu (data Validation)? - Excel

View Content
Hello everyone.

I have an spreadsheet with a number of formulas that are, among other things, influenced by the values selected from a number of drop-down menus. Through the data validation option I can prevent users from entering an incorrect value (e.g.: entering "D" when the drop-down menu only shows "A", "B" and "C"). However, since that cell has be unlocked for it to be editable, I cannot prevent the user from clearing the cell (deleting its content), which makes many other key cells in the spreadsheet go "N/A".

How can I prevent the cell from being cleared?

Thanks.

Data Validation / Drop Down Menu For An Excel Sheet From A Database - Excel

View Content
Hi All,

Firstly, A Happy New Year & thanks in advance for looking at this post.

I am actually looking to set up a drop down in an Excel sheet from a database (sql server)

Can you explain me in detail how I can do that please.

I have a list of names in the Column "Name" in a table "Staff" & Server "BT6531" which is the database. We are using SQL Server.
I am designing an excel sheet "StaffInfo.xls" in which a cell "K2" should pick up all the Values of "Name" & give them as a drop-down list for a user to select one.

Can you explain me how to do this please.

Ps. This list is dynamic & the table gets updated on regular basis.

Drop Down Menu-how Do You Produce A Drop Down Menu In A Single Cell In Excel - Excel

View Content
How do you produce a drop down menu in a single cell in Excel


Data Validation For Drop Down Menu? - Excel

View Content
I am doing an internship in Germany, and I have this crazy project with Excel. I am not very familiar with all the equations. Could somebody give me a few tips on how to go about this problem:

I want to select a company name and a type of container from a drop down menu, and have the information show up on a different sheet assigned for that specific company for the right size container. It involves quantities.

I will attach what I have sofar.
Thank you for the help, hint, or a link to a similar problem.

Ty
Ladungstraeger(1).xlsx

Ladungstraeger(2).xls

Data Validation/drop Menu With Hyperlinks? - Excel

View Content
Hello Everyone... I need some serious help as I need to put together a report for work.


What I want to do is this:


Create a drop menu. The options within the drop menu to be links (either to another Excel worksheet within the same workbook, or a WORD document).


I know how to create a drop menu, that is simple, but am not sure how to do the hyperlink aspect.


It seems when I actually insert>hyperlink onto the actual text of the drop menu (on the other sheet where i created the drop menu data), the hyperlink is not active in the actual drop menu itself.

Can somebody please help me?

Data Validation / Drop Down Menu From A Database - Excel

View Content
Hi All,

Firstly, A Happy New Year & thanks in advance for looking at this post.

I am actually looking to set up a drop down in an Excel sheet from a database (sql server)

Can you explain me in detail how I can do that please.

I have a list of names in the Column "Name" in a table "Staff" & Server "BT6531" which is the database. We are using SQL Server.
I am designing an excel sheet "StaffInfo.xls" in which a cell "K2" should pick up all the Values of "Name" & give them as a drop-down list for a user to select one.

Can you explain me how to do this please.

Ps. This list is dynamic & the table gets updated on regular basis.

Run By Selecting A Drop-down Menu From Data Validation - Excel

View Content
I was wondering if it was possible to run a macro as soon as something is selected from a drop down menu?

Data Validation / Drop Down Menu With Paste Special - Excel

View Content
Hi There!
I know how to use the copy and paste special to copy a formula from one row down many rows in that same column.

When I do this the formula will automatically change by 1 number
{such as =IF(ISBLANK(C5),"",VLOOKUP($C5,Sheet1!$B$3:D4891,3,FALSE)) then when I click on copy and pasted special each following row will change by one number ---- to =IF(ISBLANK(C6),"",VLOOKUP($C6,Sheet1!$B$3:D4892,3,FALSE))

Can this also be done if the row you want to copy and paste is a row with data validation / a drop down menu?
I simply tried using the same process for a row that has data validation the row with the validation has for the source =INDIRECT($B$5)

Is there a way to copy this down about 20 rows and have the ($B$5) change in each row by one number {such as ($B$6 THEN $B$7, ETC...)
Or do I just have to do the whole data validation process for each row?

Thanks!

Data Validation Drop-down Menu Blank Entry - Excel

View Content
I assign "names" equipment for worksheet1 COLUMN 'B' that contain

A B
1
2 primary
3 secondary
4 tool
5 gauge
6 cutter
7
8
9
10
11
12
...


For worksheet2 I assign cell b2 as data validation

Allow -> list
Source = equipment
Ignore blank -> check


However, after I copy the data validation to the rest of the row, something
weird happen

From cell b3 onward, clicking on the drop-down show the last blank cell
first, instead of showing the 1st value "primary".
The next cell b4, however doesnt have the 1st value "primary"
Cell b5 doesnt have 1st and 2nd value, and so on so forth,






Data Validation List With Unique Values (drop Down Menu) - Excel

View Content
I have a column of numbers which contains numerous repeated entries and blank cells. The list is free to expand as people can continually add to the list. The list can only expand to a finite number of rows, say 150.

Is it possible to use a bit of VB code to extract only unique entries and non-blanks from this list and copy it to another area so that this "new_list" can be named and used as data validation for a drop down menu.

I would like it to be automated so the length of the new_list created is recognised by the data validation so that there are not numerous blanks at the bottom of the drop-down menu as may be the case if numerous duplicate entries and blanks are removed.

I would be extremely greatful for any assistance.

PS I have looked at many related threads and although many solutions closely approach the one I require there are no direct matches. I am not a seasoned professional when it comes to excel so if I have failed to explain my situation using the correct terminology then please feel free to ask for further explanation.

Thanks in advance for any assistance offered!!

Random Tutorials
FV() Find the Future Value of Cash Today
         -Savings/Retirement Plan Calculations

(Intermediate)
Extract Text from Cells - Intermediate Example
(Intermediate)
AND(), OR(), and IF() Statements/Formulas
(Intermediate)
Link Cells Between Worksheets
(Easy)
Assign a Macro to a Button and Toolbar
(Intermediate)
Formatting Worksheets for Printing in Excel
(Easy)
Submit Inquiry Here
  • Prices From $10
Name:*
E-mail:*
Request:*
The macro(s) on this page will be sent with the request.
Contact | Privacy Policy | Disclaimer
Copyright© 2012 TeachExcel.com