Estadísticas de la versión: 1.0 - Lista desplegable con campo de busqueda - Visual Basic para Aplicaciones

Imágen de perfil
Val: 47
Ha aumentado 1 puesto en Visual Basic para Aplicaciones (en relación al último mes)
Gráfica de Visual Basic para Aplicaciones

Lista desplegable con campo de busquedagráfica de visualizaciones


Visual Basic para Aplicaciones

Publicado el 10 de Junio del 2020 por Aitor (6 códigos)
2.200 visualizaciones desde el 10 de Junio del 2020
Userform para mostrar la lista desplegable de la celda donde se haga el doble
click si la celda tiene una lista de validación datos dispuesta

Userform to display the drop-down list of the cell where you double-click if
the cell has a data validation list arranged
1
2
3
4
5
6
7
8
9
10
11
12
13
14
+---+-------------------------+
|  ? | TextBox1                |
+---+-------------------------+
| ListBox1                       |
| ListBox1                       |
| ListBox1                       |
| ListBox1                       |
| ListBox1                       |
| ListBox1                       |
| ListBox1                       |
| ListBox1                       |
| ListBox1                       |
| ListBox1                       |
+------------------------------+

IMPLEMENTACION/IMPLEMENTATION
=============================
En el explorador de proyectos del editor de Visual Basic
Importar el fichero frmOptionsListWithSearch.frm (asociado a frmOptionsListWithSearch.frx)
Este UserForm se activa introduciendo el metodo Sub Worksheet_BeforeDoubleClick en la parte de
código de las hojas en la que se quiere implementar en aquellas celdas con lista de
validación de datos esta opción de disponer listas desplegables con concepto de búsqueda.

In the Visual Basic editor project explorer Import the file frmOptionsListWithSearch.frm
(associated with frmOptionsListWithSearch.frx)
This UserForm is activated by introducing the Sub Worksheet_BeforeDoubleClick method in the
part of code of the sheets in which you want to implement in those cells with a data validation
list this option to have drop-down lists with a search concept.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Option Explicit
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    '---------------------------------------------------------------------------------------
    ' Method : Worksheet_BeforeDoubleClick
    ' Author : Aitor Solozabal Merino - aitorsolozabal@gmail.com
    ' Date   : 10/06/2020
    ' Purpose: Activar la lista desplegable con busqueda si se hace doble click en una celda
    '          con validacion de datos tipo lista (dropdownlist)
    '---------------------------------------------------------------------------------------
    On Error GoTo Worksheet_BeforeDoubleClick_Error
    If Not Intersect(Target, ActiveSheet.UsedRange.SpecialCells(xlCellTypeAllValidation)) Is Nothing Then
        If Target.Validation.Type = xlValidateList Then
            Cancel = True
            frmOptionsListWithSearch.Show
        End If
    End If
    On Error GoTo 0
    Exit Sub
Worksheet_BeforeDoubleClick_Error:
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Worksheet_BeforeDoubleClick of Hoja1(ejemplo)"
End Sub

También se puede disponer una macro "Activate_OptionsListWithSearch" en un modulo ó en el código de ThisWorkbook que llame a este UserForm y que con una combinación de teclas Ejemplo: CTRL+b en una celda con lista de validación de datos aparezca la lista desplegable con busqueda.

A macro "Activate_OptionsListWithSearch" can also be arranged in a module or in the ThisWorkbook code that calls this
UserForm and with a key combination Example: CTRL + b in a cell with data validation list, the drop-down list with search appears .

1
2
3
4
5
Option Explicit
 
Public Sub Activate_OptionsListWithSearch()
    frmOptionsListWithSearch.Show
End Sub

FUNCIONAMIENTO/ OPERATION
==========================
Una vez establecidas celdas en la hoja de cálculo con listas de validación de datos de los tipos:
"=G5:G35" ó "=un_nombre_definido_de_rango_de_celdas" ó "Lunes,Martes,Miércoles,Jueves,Viernes"
Si se pulsa 2 veces (Double Click) con el ratón en una celda que tiene una lista de validación
de datos se activará esta opción.
Una vez activado el UserForm en TextBox1 se pone el concepto a buscar en la lista de
validación de la celda activa y en ListBox1 aparece la lista de opciones disponibles de
acuerdo al concepto a buscar.
Si el concepto a buscar en TextBox1 no existe entonces en ListBox1 aparece toda la lista
de la validación de datos de la celda activa.
Si se esta posicionado en una opción de la lista en ListBox1 y se pulsa Return,Enter,Intro
esa opción pasa a la celda en cuestión y avanza una fila la celda activa.
Si se esta posicionado en una opción de la lista en ListBox1 y se pulsa 2 veces con el ratón
esa opción pasa a la celda en cuestión y avanza una fila la celda activa.
Si se pulsa la tecla Escape y hay un concepto a buscar introducido este se borra y se
refresca la lista completa y si no hay ningún concepto a buscar se entiende que se quiere
salir de la lista como si se pulsase en la [X] de la esquina superior derecha de la ventana.
Si en la celda ya hay un valor anteriormente introducido aparecerá en la lista como escogido.

Once cells have been established in the spreadsheet with data validation lists of the types:
"=G5:G35" or "=a_defined_name_of_range_of_cells" or "Monday, Tuesday, Wednesday, Thursday, Friday"
If you double-click with a mouse in a cell that has a validation list this option will be activated.
Once the UserForm is activated the concept to search for in the list of validation of the active cell
is set in the TextBox1 area of the Userform, and in the ListBox1 area of the Userform is the list of
available options according to the concept to search for.
If the concept to search in TextBox1 does not exist, then the entire options list of the data validation
of the active cell appears in ListBox1.
If you are positioned in a list option in ListBox1 and press Return/Enter key that option moves to the
active cell value and after that advances the active cell one row.
If you are positioned in an option of the list in ListBox1 and you double click with the mouse that
option moves to the active cell value and after that advances the active cell one row.
If the Escape key is pressed and there is a concept to search for in the TextBox1, it is deleted and
Generate the complete options list and if there is no concept to search for, it is understood that you
want exit the list as if you clicked the [X] in the upper right corner of the window.
If there is a previously entered value in the active cell, it will appear in the list as it is chosen currently.

1.0

Publicado el 10 de Junio del 2020
2.200 visualizaciones desde el 10 de Junio del 2020

176 visualizaciones durante los últimos 90 días


25
0