Macro para hacer modificaciones en varias al mismo tiempo

Para

Elsa matilde

Quiero hacer modificaciones a registros en varias hojas al mismo tiempo

Agrego registro en hoja2 que también se agrega a la hoja20

Pero al querer hacerle alguna modificación al mismo registro solo se modifica en la hoja2 pero no en la hoja20, en la hoja20 se agrega como nuevo registro y esto hace que hayan 2 registros similares.

Le envío los datos y el archivo a su correo

1 Respuesta

Respuesta
2

Esto es porque utilizas la misma macro tanto sea para Agregar como para Modificar, entonces siempre agrega un registro al final.

Así es cómo debiera quedarte esa macro:

Sub movimientos()
Dim TransRowRng As Range
Dim NewRow As Integer
'declaro la hoja para no tener que activarla
Set hm = Sheets("Movimientos")
'separar el proceso ya sea Agregar o Modificar
If OptionButton6.Value = True Then     'Agregar
    Set TransRowRng = hm.Cells(1, 1).CurrentRegion
        NewRow = TransRowRng.Rows.Count + 1
        With hm
            .Cells(NewRow, 1).Value = Me.TextBox1
            .Cells(NewRow, 3).Value = Me.txt_conteofisico
            .Cells(NewRow, 8).Value = Me.txt_fechaven
            .Cells(NewRow, 9).Value = Me.txt_numerolote
            .Cells(NewRow, 10).Value = Range("O3").Value
        End With
    With hm.UsedRange
            .Borders(xlEdgeLeft).LineStyle = xlContinuous
            .Borders(xlEdgeTop).LineStyle = xlContinuous
            .Borders(xlEdgeBottom).LineStyle = xlContinuous
            .Borders(xlEdgeRight).LineStyle = xlContinuous
            .Borders(xlInsideVertical).LineStyle = xlContinuous
            .Borders(xlInsideHorizontal).LineStyle = xlContinuous
    End With
    hm.Range("B:J").HorizontalAlignment = xlCenter
Else
    'se busca el registro en col A para modificarlo
    Set busco = hm.Range("A:A").Find(TextBox1, LookIn:=xlValues, lookat:=xlWhole)
    'si encuentra el elemento lo modifica, sino comenta
    If Not busco Is Nothing Then
        NewRow = busco.Row
        With hm
            .Cells(NewRow, 1).Value = Me.TextBox1
            .Cells(NewRow, 3).Value = Me.txt_conteofisico
            .Cells(NewRow, 8).Value = Me.txt_fechaven
            .Cells(NewRow, 9).Value = Me.txt_numerolote
            .Cells(NewRow, 10).Value = Range("O3").Value
        End With
    Else
        MsgBox "No se encontró este producto en hoja 'Movimientos'.", , "ATENCIÓN"
    End If
End If
End Sub

PD) No olvides colocar la siguiente instrucción al inicio de las subrutinas que realizan cambios en las hojas para evitar ver el movimiento: 

Application.ScreenUpdating = False

¡Gracias! 

problema solucionado

saludos

Bien. Y recuerda valorar la respuesta para darla por cerrada.

Sdos!

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas