Showing posts with label Selection. Show all posts
Showing posts with label Selection. Show all posts

February 06, 2016

Microsoft Excel Select a value from a predefined list of values with dropdown option to validate the data

Hi friends,

When I was preparing a sheet by referencing some pre-defined names as list to a field/cell. I was thinking the feature of Microsoft Excel dropdown list. After exploring the option and using, I thought of sharing with you all.

Objective: Selecting a cell value from a list of pre-defined values

Procedure:
  1. Open blank excel workbook
  2. Prepare you template with headers
  3. Create a new sheet and rename it. Ex: "Names"
  4. Enter the values from Column A from cell A1 in vertical direction
  5. Don't use any other columns
  6. Don't leave any empty cell in between the values
  7. Leave first cell as empty, if you want to include the empty option in a dropdown
  8. Select the cell which contains the values
  9. Right click and choose the option "Define Name"
  10. Give a name to the list of values. Ex: NamesList
  11. Click on "OK" button
  12. Now, move to the sheet where we want to use the list of names as a dropdown option
  13. Select the cell(s), where we want to have the dropdown list
  14. Click on "Data" Menu
  15. From "Data Tools" ribbon, click "Data Validation" from "Data Validation" submenu
  16. In Settings tab, Validation Criteria section, for the option Allow, select "List"
  17. Choose the options
    • Ignore blank: Ignore when user no selected any option
    • In-cell Dropdown: Show the dropdown list in cell
  18. In "Source" field, type the defined name for the list preceded with = (Equal to) symbol. Ex: =NamesList
  19. Now, you should be able to see the dropdown with empty values
  20. Select the predefined values from the dropdown list of names.
Please send your comments and feedback to psrdotcom@gmail.com

    September 09, 2010

    Excel VBA: Multi-selection Listbox using pop-up window to display column values

    Description:

    We have following excel sheet with the two columns Names and Requirednames.
    Names column has all the names
    Required Names column should have some selected name(s)

    Names Required Names
    ABC,DEF,GHI  
       
    PSR,DOT,COM  


    What we can do other than copy and paste?

    We can create a pop-up window which will display all the names by using list box and we can select the required names from that list box.

    Procedure:
    1.Go to Developer Tab -> Design Mode
    2.Click on Insert and click -> CommandButton
    3.Drag the cursor to create a button
    4.Rename button with name "Show Names" in sheet
    5.Assign a macro to it with name "DisplayNames"
    6.Open VBEditor
    7.Goto Insert -> User Form
    8.We will get one form, Design the form as follows
    9.
    UserForm1



    10.Change Caption to "Names Selection" in Form Properties
    11.Change Caption to "List of Names" in Frame Properties
    12.Change Caption to "Select the names and click OK" in Lable Properties
    13.Change Name to "lbEmp", MultiSelect to 1-fmMultiSelectMulti in ListBox Properties
    14.Change Name to "submit" and Caption to "OK" in Button1 Properties
    15.Change Name to "close" and Caption to "Close" in Button2 Properties
    16.Change Name to "reset" and Caption to "Reset" in Button3 Properties
    17.Select Excel window, Go to Macros and Select "DisplayNames" macro(which is already assigned to the Button in Sheet), Click on Edit
    18.Write the following code:
    Dim rngEmp() As String
    Dim emps As String
    Dim i As Integer

    Application.Sheets("Sheet1").Select
    emps = ActiveCell.Offset(0, -1).Value
    If emps = "" Then
    MsgBox ("No Name(s) Available")
    End
    Else
    rngEmp = Split(emps, ",")
    End If

    For i = LBound(rngEmp) To UBound(rngEmp)
    UserForm1.lbEmp.AddItem rngEmp(i)
    Next

    UserForm1.Show
    19.
    Double-click on the UserForm1 from the Forms directory in VBEditor
    20.
    Double-click on any one of the button on the form to view code(shortcut: F7)
    21.
    Select all the code and delete it. Paste the following code

    Private Sub close_Click()
    Unload UserForm1
    End Sub
    Private Sub reset_Click()
    UserForm1.lbEmp.Clear
    End Sub
    Private Sub submit_Click()
    Dim emps As String
    emps = ""
    For i = 0 To UserForm1.lbEmp.ListCount - 1
    If lbEmp.Selected(i) = True Then
    'MsgBox lbEmp.List(i)
    If emps = "" Then
    emps = lbEmp.List(i)
    ElseIf emps <> "" Then
    emps = emps & "," & lbEmp.List(i)
    End If
    End If
    Next i
    ActiveCell.Value = emps
    End Sub
    21.Save and Close the VBEditor. Goto Excel sheet
    22.Select the right adjacent Cell say B1 Cell
    23.Click the button which we created on the sheet
    24.Select the name(s) and Click Ok to see values in the selected cell
    25.We can select Multiple Names at a time which will display names with the delimiter "," in the selected cell
    26.If A's cell doesn't contain any value then it will display a message "No Name(s) Available"
    27.We have to select Close to close the pop-up window
    28.We can select Clear to clear list and then select close to cancel

    You can see the sample output

    Names Required Names
    ABC,DEF,GHI ABC
       
    PSR,DOT,COM PSR,COM

    Note:
    For any further queries and/or suggestions please contact psrdotcom@gmail.com

    Featured Post

    Java Introdcution

    Please send your review and feedback to psrdotcom@gmail.com