Macro para seleccionar siguiente item de Lista desplegable sin dar click en la lista. Lo mismo para seleccionar el anterior item

Hola, quisiera que me ayudaran a programar la forma en que pueda seleccionar el siguiente y anterio elemento de la lista a través de los botones "Anterior" y "Siguiente", para evitar estar dando clic en la lista y seleccionando cada elemento.

Si no hay más elementos, debe generar un mensaje que me diga que ese fue el ultimo, lo mismo si es el primer elemento y pretendo ir hacia atrás.

Aunque también quisiera que más bien del mensaje, mejor deshabilite el botón si es que no hay más elementos o si es el primero.

1 Respuesta

Respuesta
2

H o l a:

Te anexo las macros

Private Sub CommandButton1_Click()
'Por.Dante Amor
    'Anterior
    CommandButton2.Enabled = True
    Set ad = ActiveCell.SpecialCells(xlCellTypeAllValidation)
    [D4].Select
    If Not Intersect(Range(ActiveCell.Address), ad) Is Nothing Then
         rango = ad.Validation.Formula1
         Set r = Range(rango)
         Set b = r.Find(ad.Value, lookat:=xlWhole)
         If Not b Is Nothing Then
            f1 = r.Cells(1, 1).Row
            f2 = b.Row
            c2 = r.Cells(1, 1).Column
            If f2 > f1 Then
                valor = Cells(b.Row - 1, c2)
                Range(ad.Address) = valor
                'Application.SendKeys "%{UP}"
            Else
                'MsgBox "No hay más elementos"
                CommandButton1.Enabled = False
            End If
        End If
    End If
End Sub
'
Private Sub CommandButton2_Click()
'Por.Dante Amor
    'Siguiente
    CommandButton1.Enabled = True
    Set ad = ActiveCell.SpecialCells(xlCellTypeAllValidation)
    [D4].Select
    If Not Intersect(Range(ActiveCell.Address), ad) Is Nothing Then
         rango = ad.Validation.Formula1
         Set r = Range(rango)
         Set b = r.Find(ad.Value, lookat:=xlWhole)
         If Not b Is Nothing Then
            f1 = r.Cells(1, 1).Row
            ff = r.Rows.Count + f1 - 1
            f2 = b.Row
            c2 = r.Cells(1, 1).Column
            If f2 < ff Then
                valor = Cells(b.Row + 1, c2)
                Range(ad.Address) = valor
                'Application.SendKeys "%{UP}"
            Else
                'MsgBox "No hay más elementos"
                CommandButton2.Enabled = False
            End If
        End If
    End If
End Sub

' : )
'S aludos. Dante Amor. Recuerda valorar la respuesta. G racias
' : )

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas