Upload
maha-hassan
View
152
Download
4
Embed Size (px)
DESCRIPTION
EXCEL VALIDATION
Citation preview
Search Contextures Sites
Home Excel Tips Excel Files Products Blog ContactRSS
Excel Data Validation Combo box Click
Create an Excel Data ValidationDropdown List Add the Combo box Open the Properties Window Change the Combo box Properties Exit Design Mode Add the Code Test the Code
Download the zipped sample file
You can use Excel Data Validation to create adropdown list of options in a cell. However, the listfont can't be changed, nor can the number of visiblerows, which has a maximum of eight. Also, DataValidation doesn't have an AutoComplete feature,which finds matching items in the list as you start totype.
To overcome these limitations, you can add a combobox to your worksheet, and use programming tomake it appear in cells that contain a data validationlist. Click on a cell that contains a data validation list,and the combo box appears. The combo box's fontsize can be set, more than 8 rows can be displayed,and autocomplete can be enabled.
If you would prefer to see the combo box only when
you double-click on a data validation cell, pleaseuse the instructions at one of the following pages:
Data Validation -- Combo Box Data Validation -- Combo Box - NamedRanges
Note: If the worksheet is protected, allow users toEdit Objects, and they will be able to use thecombobox.
Gantt Chart Templatewww.smartsheet.com
Yes, it's easy. Nothing to install. Try it Free!
Excel Data Validation Combo box Click http://www.contextures.com/xlDataVal14.html
1 of 5 11/26/2013 9:25 PM
Create a Data ValidationDropdown List
On Sheet1, type the lists that will be used in the datavalidation dropdowns:
Tip: Use the AutoFill feature to create the lists
In cells K2:K8 type a list of weekdays1.
In cells M2:M13 type a list of months 2.
The next step is to create the data validation dropdownlists. There are detailed instructions here: Data Validation-- Introduction
Cells C2:C12 have data validation lists with the source
K2:K8. When a cell in this range is selected, a
dropdown list of weekdays is available.
Cells D2:D12 have data validation lists with the source
M2:M13. When a cell in this range is selected, a
dropdown list of months is available.
Add the Combo box
To add or edit the Combobox, open the Control Toolbox,and enter Design Mode:
Choose View | Toolbars1.
Select Control Toolbox2.
Click the Design Mode button3.
Click on the Combo box button, to activate that tool.4.
Click on an empty area of the worksheet, to add a
combo box
5.
Open the Properties Window
To format the combo box, open the properties window:
Select the combo box1.
On the Control Toolbox, click the Properties button2.
Change the Combo boxProperties
Name the Combo box
In the Properties window, click in the Name box1.
Type a name for the combo box. In this example, the
name is: TempCombo
2.
Excel Data Validation Combo box Click http://www.contextures.com/xlDataVal14.html
2 of 5 11/26/2013 9:25 PM
Change the Font and Font Size
In the Properties window, click in the Font property,
and click the ... button
1.
In the Font dialog box, select a font, font size, and
other settings that you want for your combo box.
2.
Click OK 3.
Set the Number of Rows
In the Properties window, click in the ListRows box1.
Type the number of rows that you want displayed in
the dropdown. In this example, the setting is: 12
2.
Turn on AutoComplete
In the Properties window, click in the MatchEntry
property
1.
From the dropdown list, select
1-frmMatchEntryComplete
2.
Exit Design Mode
Close the Properties window1.
On the Control Toolbox, click the Exit Design Mode
button
2.
Add the Code
Visual Basic for Applications (VBA) code is required to make the combo boxappear when you click in a cell that contains a data validation list.
Copy the following code:
'=========================================
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim str As String
Dim cboTemp As OLEObject
Dim ws As Worksheet
Set ws = ActiveSheet
On Error GoTo errHandler
If Target.Count > 1 Then GoTo exitHandler
Set cboTemp = ws.OLEObjects("TempCombo")
On Error Resume Next
If cboTemp.Visible = True Then
Excel Data Validation Combo box Click http://www.contextures.com/xlDataVal14.html
3 of 5 11/26/2013 9:25 PM
With cboTemp
.Top = 10
.Left = 10
.ListFillRange = ""
.LinkedCell = ""
.Visible = False
.Value = ""
End With
End If
On Error GoTo errHandler
If Target.Validation.Type = 3 Then
'if the cell contains a data validation list
Application.EnableEvents = False
'get the data validation formula
str = Target.Validation.Formula1
str = Right(str, Len(str) - 1)
With cboTemp
'show the combobox with the list
.Visible = True
.Left = Target.Left
.Top = Target.Top
.Width = Target.Width + 15
.Height = Target.Height + 5
.ListFillRange = ws.Range(str).Address
.LinkedCell = Target.Address
End With
cboTemp.Activate
'open the drop down list automatically
Me.TempCombo.DropDown
End If
exitHandler:
Application.ScreenUpdating = True
Application.EnableEvents = True
Exit Sub
errHandler:
Resume exitHandler
End Sub
'====================================
'Optional code to move to next cell if Tab or Enter are pressed
'from code by Ted Lanham
'***NOTE: if KeyDown causes problems, change to KeyUp
Private Sub TempCombo_KeyDown(ByVal _
KeyCode As MSForms.ReturnInteger, _
ByVal Shift As Integer)
Select Case KeyCode
Case 9 'Tab
ActiveCell.Offset(0, 1).Activate
Case 13 'Enter
ActiveCell.Offset(1, 0).Activate
Case Else
'do nothing
End Select
End Sub
'====================================
To add this code to the worksheet:
Right-click on the sheet tab, and choose View Code.1.
Choose Edit | Paste, to paste the code onto the sheet
module, where the cursor is flashing.
2.
Choose File | Close and Return to Microsoft Excel. 3.
Test the Code
Click on one of the cells that contains a data
validation list.
1.
The combo box will appear2.
Select an item from the combo box dropdown list3.
Click on a different cell, to select it4.
The selected item appears in previous cell, and the
combo box disappears.
5.
Download the sample file
PerformanceDashboardsCorporater.com/Perfor
Build executive
dashboards with KPIs,
initiatives and more.See
Demo
…
Self-ConfidenceWorkshops
SpreadsheetProfessional
Learn Macrosfor Excel
DescriptiveStats Macro
Excel Data Validation Combo box Click http://www.contextures.com/xlDataVal14.html
4 of 5 11/26/2013 9:25 PM
Excel Tutorials - Data Validation
Data Validation BasicsData Validation - Create Dependent ListsData Validation - Dependent Dropdowns from aSorted List Data Validation - Dependent Lists With INDEX Hide Previously Used Items in a Dropdown ListData Validation - Display Messages to the UserData Validation - Display Input Messages in aText Box Data Validation - Use a List from AnotherWorkbookData Validation Criteria ExamplesData Validation Custom Criteria ExamplesData Validation TipsData Validation DocumentationData Validation Combo Box Data Validation Combo Box - Named RangesData Validation Combo Box -- ClickData Validation - Add New Items
Home Excel Tips Excel Files Products Blog Contact
PrivacyPolicy
Contextures Inc., Copyright ©2013All rights reserved.
Debra Dalgleish
Last updated: July 11, 2013 4:34 PM
Excel Data Validation Combo box Click http://www.contextures.com/xlDataVal14.html
5 of 5 11/26/2013 9:25 PM