Get the App
SLTechnology News&Howtos  ›  Development  › 

How to implement vba validity verification drop-down multi-selection

Shulou Source: shulou.com Published: 2022-06-03 06:58:02 09月30日 Update

This article mainly introduces "how to achieve vba validity verification drop-down multiple selection". In the daily operation, I believe that many people have doubts about how to achieve vba validity verification pull-down multiple selection. The editor consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubt of "how to achieve vba validity verification drop-down multiple selection". Next, please follow the editor to study!

Validity verification drop-down multiple selection

Create a drop-down menu

Set the multi-selection code:

Sub Worksheet_Change (ByVal Target As Range) Dim xRng As Range Dim xValue1 As String Dim xValue2 As String'in order to ensure that the user only selects a single cell If Target.Count > 1 Then Exit Sub 'when adding the On Error Resume Next statement, if the later program has a "runtime error", it will continue to run without interruption. On Error Resume Next 'locates a cell with validation conditions Set xRng = Cells.SpecialCells (xlCellTypeAllValidation) If xRng Is Nothing Then Exit Sub Application.EnableEvents = False' Intersect function returns a partial example of two or more cells overlapping: Intersect (Range ('a1Cells.SpecialCells d5'), Range (' c4Cells.SpecialCells g9')) If Not Application.Intersect (Target XRng) Is Nothing Then xValue2 = Target.Value 'event response If the worksheet changes, Undo, undo the table Application.Undo xValue1 = Target.Value Target.Value = xValue2 If xValue1 "" Then If xValue2 "" Then 'InStr function' the first parameter 1 means to start the search from the first location of the xValue1 'The string to search for the second parameter 'string found by the third parameter'& string concatenation If xValue1 = xValue2 Or InStr (1, xValue1, ", & xValue2) Or InStr (1, xValue1, xValue2 &",) Then Target.Value = xValue1 Else Target.Value = xValue1 & " "& xValue2 End If Application.EnableEvents = True End Sub

At this point, the study on "how to achieve vba validity verification drop-down multiple selection" is over. I hope to be able to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Validate validate Lado learn unit parameter character string function more help search run utility next two event code representative Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker macOS Shulou Information vpn Apple