Saltar al contenido principal

¿Cómo borrar la celda de la lista desplegable dependiente después de seleccionar cambiado en Excel?

Para una lista desplegable dependiente, cuando se cambia el valor de la lista desplegable principal, el valor seleccionado en la segunda no será válido. Debe eliminar manualmente el valor no válido de la segunda lista desplegable después de seleccionar cambiado en la primera. En este artículo, le mostraré un método para borrar automáticamente la celda de la lista desplegable dependiente después de seleccionar cambiado en Excel.

Borrar la celda de la lista desplegable dependiente después de seleccionar cambiado con el código VBA


Borrar la celda de la lista desplegable dependiente después de seleccionar cambiado con el código VBA

El siguiente código de VBA le ayuda a borrar la lista desplegable dependiente después de seleccionar cambiado en Excel.

1. Haga clic derecho en la pestaña de la hoja que contiene la lista desplegable dependiente que borrará automáticamente, luego seleccione Ver código desde el menú contextual.

2. En la apertura Microsoft Visual Basic para aplicaciones ventana, copie debajo del código VBA en la ventana.

Código de VBA: borrar la celda de la lista desplegable dependiente después de seleccionar cambiado

Private Sub Worksheet_Change(ByVal Target As Range)
'Update by Extendoffice 2018/06/04
    Application.EnableEvents = False
    If Target.Column = 5 And Target.Validation.Type = 3 Then
        Target.Offset(0, 1).Value = ""
    End If
    Application.EnableEvents = True
End Sub

Note: En el código, el número 5 es el número de columna que contiene la lista desplegable principal. En este caso, mi lista desplegable de padres se ubica en la columna E.

3. presione el otro + Q llaves para cerrar el Microsoft Visual Basic para aplicaciones ventana.

De ahora en adelante, cuando se realicen cambios en la lista desplegable principal, el contenido de la segunda lista desplegable se borrará automáticamente. Ver captura de pantalla:


Artículos relacionados:

Las mejores herramientas de productividad de oficina

🤖 Asistente de IA de Kutools: Revolucionar el análisis de datos basado en: Ejecución inteligente   |  Generar codigo  |  Crear fórmulas personalizadas  |  Analizar datos y generar gráficos  |  Invocar funciones de Kutools...
Características populares: Buscar, resaltar o identificar duplicados   |  Eliminar filas en blanco   |  Combine columnas o celdas sin perder datos   |   Ronda sin fórmula ...
Super búsqueda: Búsqueda virtual de criterios múltiples    Búsqueda V de valores múltiples  |   VLookup en varias hojas   |   Búsqueda difusa ....
Lista desplegable avanzada: Crear rápidamente una lista desplegable   |  Lista desplegable dependiente   |  Lista desplegable de selección múltiple ....
Administrador de columnas: Agregar un número específico de columnas  |  Mover columnas  |  Toggle Estado de visibilidad de columnas ocultas  |  Comparar rangos y columnas ...
Características destacadas: Enfoque de cuadrícula   |  Vista de diseño   |   Gran barra de fórmulas    Administrador de hojas y libros de trabajo   |  Biblioteca de Recursos (Texto automático)   |  Selector de fechas   |  Combinar hojas de trabajo   |  Cifrar/descifrar celdas    Enviar correos electrónicos por lista   |  Súper filtro   |   Filtro especial (filtro negrita/cursiva/tachado...) ...
Los 15 mejores conjuntos de herramientas12 Texto Herramientas (Añadir texto, Quitar caracteres, ...)   |   50+ Tabla Tipos (Diagrama de Gantt, ...)   |   40+ Práctico Fórmulas (Calcular la edad según el cumpleaños, ...)   |   19 Inserción Herramientas (Insertar código QR, Insertar imagen desde la ruta, ...)   |   12 Conversión Herramientas (Números a palabras, Conversión de Moneda, ...)   |   7 Fusionar y dividir Herramientas (Filas combinadas avanzadas, Células partidas, ...)   |   ... y más

Mejore sus habilidades de Excel con Kutools for Excel y experimente la eficiencia como nunca antes. Kutools for Excel ofrece más de 300 funciones avanzadas para aumentar la productividad y ahorrar tiempo.  Haga clic aquí para obtener la función que más necesita...

Descripción


Office Tab lleva la interfaz con pestañas a Office y hace que su trabajo sea mucho más fácil

  • Habilite la edición y lectura con pestañas en Word, Excel, PowerPoint, Publisher, Access, Visio y Project.
  • Abra y cree varios documentos en nuevas pestañas de la misma ventana, en lugar de en nuevas ventanas.
  • ¡Aumenta su productividad en un 50% y reduce cientos de clics del mouse todos los días!
Comments (9)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Deleting Multiple rows gives error. Any suggestions ?
This comment was minimized by the moderator on the site
I was getting errors with multiple row deletion as well as rows being deleted that shouldn't have been cleared. Below is the solution that worked for me.

Private Sub Worksheet_Change(ByVal Target As Range)
'Update by D 2022/08/23
On Error Resume Next
Application.EnableEvents = False
If Target.Column = 9 Then
If Target.Validation.Type = 3 Then
Application.EnableEvents = False
Target.Offset(0, 4).Value = ""
End If
End If

Application.EnableEvents = False
If Target.Column = 9 Then
If Target.Validation.Type = 3 Then
Application.EnableEvents = False
Target.Offset(0, 5).Value = ""
End If
End If

Application.EnableEvents = False
If Target.Column = 13 Then
If Target.Validation.Type = 3 Then
Application.EnableEvents = False
Target.Offset(0, 1).Value = ""
End If
End If

exitHandler:
Application.EnableEvents = True
Exit Sub

End Sub
This comment was minimized by the moderator on the site
I am trying to have this apply to two dependent drop downs and cannot seem to get the code right. I tried copying the code and updating the offset and using the and function and get an error each time. Any advice? I want the two columns next to the drop down to clear if it is changed instead of just one.
This comment was minimized by the moderator on the site
Hi, this is how I got it working for multiple drop downs, the "And" function didn't work for me either but this seems to. Essentially you need a different "If" statement for each drop down you want to go blank when you change the chosen value in the first drop down menu. There may be a more efficient way to do this but this worked for me!


Private Sub Worksheet_Change(ByVal Target As Range)
'Update by Extendoffice 2018/06/04
Application.EnableEvents = False
If Target.Column = 2 And Target.Validation.Type = 3 Then
Target.Offset(0, 1).Value = ""
End If
If Target.Column = 2 And Target.Validation.Type = 3 Then
Target.Offset(0, 2).Value = ""
End If
If Target.Column = 2 And Target.Validation.Type = 3 Then
Target.Offset(0, 3).Value = ""
End If
If Target.Column = 2 And Target.Validation.Type = 3 Then
Target.Offset(0, 4).Value = ""
End If
Application.EnableEvents = True
End Sub
This comment was minimized by the moderator on the site
It does not work.
This comment was minimized by the moderator on the site
Hi Marlborek,
Which Excel version are you using?
This comment was minimized by the moderator on the site
Working Perfectly
This comment was minimized by the moderator on the site
To post as a guest, your comment is unpublished.
This comment was minimized by the moderator on the site
سلام وقت شما بخیر
ما فایل اکسلی داریم که خروجیش از طریق نرم افزار همکاران سیستم هست یعنی فایل اکسل ما آنلاین به data base نرم افزار همکاران متصله(این مهم نیست برای اطلاع عرض کردم) توی این فایل فیلترهایی وجود داره که هر فیلتر یک لیست کشویی داره مشکل ما اینه که وقتی میخواهیم هر کدوم از فیلتر ها یکی از موارد لیست کشویی رو انتخاب کنیم با انتخاب لیست،لیست کشویی زود می پره یعنی بسته میشه زود و نمیشه چیزی رو انتخاب کرد،اینم بگم خدمتتون که آفیس رو حذف و نصب هم کردم بازم جواب نداد یعنی یه مدت خیلی کوتاهی جواب میده بعد به حالت قبل بر میگرده با پشتیبانی همکاران هم تماس گرفتیم گفتن مشکل از آفیستونه
(آفیسمون 2016 هست)یعنی عملا اونها هم نتونستن مشکل رو پیدا کنن.
لطفا اگه راهی هست ممنون میشم راهنماییم کنید.
با تشکر
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations