Buscar datos y modificarlos abriendo ventana o useform en hoja origen

Se trataría de realizar las búsquedas de datos y las modificaciones desde la hoja origen "Titulos" bien abriendo una ventana emergente una vez tengo abierta la hoja "Titulos" o mediante un useform que se visualizara encima de la hoja, una vez he metido los datos en el inputbox.

La verdad es que he visto que me resulta más cómodo buscar y modificar datos visualizando la hoja origen sin tener que abrir una segunda hoja para verlos.

Realmente no quiero que los resultados de las búsquedas de datos aparezcan en la hoja "titulos"... Me refiero a que teniendo abierta esta hoja pulsara un botón "buscar", introdujera los datos en el inputbox y entonces me apareciera una ventana emergente (más pequeña que la hoja "Titulos") o un useform, con los datos de la búsqueda (nºfila y titulos) y con el botón de modificar. El objetivo es visualizar todo en una misma hoja.

1 respuesta

Respuesta
1

H o l a:

Puede ser con un formulario. Este podría ser el diseño, en la misma hoja tendrías un botón para abrir el formulario.

En el formulario tendrías un textbox para introducir la palabra y un botón para buscar, en el mismo formulario, en un listbox te aparecerían los títulos encontrados.


Para modificar un título, una opción es que presiones dobleclick sobre el título, entonces se abrirá una ventana para que captures el nuevo nombre, por default, te aparecería el título a modificar; escribirías el nuevo nombre y presionas Aceptar para guardar los cambios.


Lo que te estoy poniendo es una idea, pero si tienes algo más en mente, entonces envíame tu diseño para ver que controles estás poniendo en el formulario y en base a eso crear las macros.


Si eliges utilizar el formulario, la primer macro que necesitas para abrir el formulario es esta, pon la siguiente macro en un módulo:

Sub Abrir()
    UserForm1.Show
End Sub

Es justo lo que necesito. Realmente lo que me propones cumple mis necesidades y queda muy bien.

Si quieres ponme un link y me descargo el archivo excel con las macros o si lo prefieres me detallas todos los pasos con el código en tu respuesta, lo que te venga mejor.

Realmente te doy las gracias porque para mí esto me soluciona el problema que tenía y encima estéticamente queda perfecto. Mil  gracias

H o l a :

Envíame un correo con un ejemplo de tu archivo y te pongo el formulario y las macros.

También te anexo las instrucciones para crear el formulario.

Como ya viste en la imagen del formulario, necesitas un textbox, un botón y un listbox con 2 columnas.

Este sería el código para el formulario, para buscar y actualizar los títulos:

Private Sub CommandButton1_Click()
'Por.Dante Amor
    Set h1 = Sheets("titulos")
    titulo = TextBox1
    If titulo = "" Then
        MsgBox "Introduce una palabra para buscar", vbExclamation, "BUSCAR"
        TextBox1.SetFocus
        Exit Sub
    End If
    '
    j = 2
    Set r = h1.Columns("A")
    Set b = r.Find(titulo, lookat:=xlPart)
    If Not b Is Nothing Then
        ncell = b.Address
        Do
            'detalle
            If h1.Cells(b.Row, "A") Like titulo Or _
               h1.Cells(b.Row, "A") Like "* " & titulo Or _
               h1.Cells(b.Row, "A") Like titulo & " *" Or _
               h1.Cells(b.Row, "A") Like "* " & titulo & " *" Then
                ListBox1.AddItem b.Row
                ListBox1.List(ListBox1.ListCount - 1, 1) = b.Value
                j = j + 1
            End If
            Set b = r.FindNext(b)
        Loop While Not b Is Nothing And b.Address <> ncell
    End If
End Sub
'
Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
'Por.Dante Amor
    tit = ListBox1.List(ListBox1.ListIndex, 1)
    nuevo = InputBox("Escribe el nuevo nombre", "CAMBIAR NOMBRE", tit)
    If nuevo = "" Then Exit Sub
    fila = ListBox1.List(ListBox1.ListIndex)
    Sheets("titulos").Cells(fila, "A") = nuevo
    ListBox1.Clear
    CommandButton1_Click
    MsgBox "Actualización realizada", vbInformation, "ACTUALIZAR TÍTULO"
End Sub

Hola

Pues muchas gracias de nuevo por todo.

Me comentas que te envíe un correo con el archivo para que me pongas el formulario y las macros... pero dónde te envío el correo, a qué dirección, si me puedes indicar.

Muchas gracias

'

Mi correo [email protected]

En el asunto del correo escribe tu nombre de usuario “deprofundis” y el título de esta pregunta.

Hola

Te acabo de enviar el archivo excel a tu correo

Gracias

 H o l a:

Te anexo las macros actualizadas

Private Sub CommandButton1_Click()
'Por.Dante Amor
    Set h1 = Sheets("titulos")
    titulo = UCase(TextBox1)
    If titulo = "" Then
        MsgBox "Introduce una palabra para buscar", vbExclamation, "BUSCAR"
        TextBox1.SetFocus
        Exit Sub
    End If
    '
    j = 2
    Set r = h1.Columns("A")
    Set b = r.Find(titulo, lookat:=xlPart)
    If Not b Is Nothing Then
        ncell = b.Address
        Do
            'detalle
            htit = UCase(h1.Cells(b.Row, "A"))
            If htit Like titulo Or _
               htit Like "* " & titulo Or _
               htit Like titulo & " *" Or _
               htit Like "* " & titulo & " *" Then
                ListBox1.AddItem b.Row
                ListBox1.List(ListBox1.ListCount - 1, 1) = b.Value
                j = j + 1
            End If
            Set b = r.FindNext(b)
        Loop While Not b Is Nothing And b.Address <> ncell
    End If
End Sub
'
Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
'Por.Dante Amor
    tit = ListBox1.List(ListBox1.ListIndex, 1)
    nuevo = InputBox("Escribe el nuevo nombre", "CAMBIAR NOMBRE", tit)
    If nuevo = "" Then Exit Sub
    fila = ListBox1.List(ListBox1.ListIndex)
    Sheets("titulos").Cells(fila, "A") = nuevo
    ListBox1.Clear
    CommandButton1_Click
    MsgBox "Actualización realizada", vbInformation, "ACTUALIZAR TÍTULO"
End Sub

'

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas