Registro de modificaciones en una fila

Tengo una matriz que es modificada a través de un userform, necesito agregar un código que registre en una celda de la fila que está siendo modificada el username de quienes lo han modificado.
1 Respuesta
Suponiendo que x = fila donde se está realizando el pase y J sea la columna donde debe ir el username, esta sería la instrucción:
Range("J" & x) = Range("J" & x) & " " & Application.UserName
Estoy adicionando el nombre del usuario a cualquier texto que ya contenga esa celda siguiendo tu imagen. Si solo debe ser colocado el nombre del último usuario quedaría como:
Range("J" & x) = Application.UserName
Private Sub CommandButton3_Click()
'---------
'Modificar
'---------
With ListBox1
Pasar_a_la_hoja 0 + .List(.ListIndex, 0)
End With
CommandButton1_Click
End Sub
Private Sub CommandButton4_Click()
'--------
'Eliminar
'--------
Dim LR&
With ListBox1
LR = 0 + .List(.ListIndex, 0)
End With
If MsgBox("¿Confirma eliminación?...", vbYesNo) = vbNo Then Exit Sub
ws1.Cells(LR, "a").Resize(, 10).Delete xlShiftUp
If ws1.[b3] <> "" Then
With ws1.Range(ws1.[b3], ws1.[b2].End(xlDown)).Offset(, -1)
.Formula = "=row()"
.Value = .Value
End With
End If
CommandButton1_Click
End Sub
Private Sub Pasar_a_la_hoja(LR&)
Dim iFase
Dim iEntrega
Dim iAccion
Dim iTurno
With ws1.Cells(LR, "a")
.Value = .Row
.Cells(1, 2) = TextBox1 ' Lote
.Cells(1, 3) = CDate(TextBox8) ' Fecha
.Cells(1, 4) = TextBox9 ' Hora
.Cells(1, 8) = Environ("Username") 'Firma de usuario
.Cells(1, 6) = 0 + ComboBox1.List(ComboBox1.ListIndex, 1) ' Producto1
.Cells(1, 27) = ComboBox1.Value 'Producto2
.Cells(1, 16) = TextBox2.Value 'Observaciones
.Cells(1, 18) = TextBox15.Value 'Fecha devolución
.Cells(1, 19) = TextBox14.Value 'Hora devolución
.Cells(1, 20) = TextBox10.Value 'Fecha recepción corrección
.Cells(1, 21) = TextBox11.Value 'Hora recepcion corrección
.Cells(1, 22) = TextBox16.Value 'Transito corrección
.Cells(1, 23) = TextBox12.Value 'Fecha entrega GC
.Cells(1, 24) = TextBox13.Value 'Hora entrega GC
.Cells(1, 25) = TextBox17.Value 'Trancito total
For Each iFase In FaseS
If Controls(iFase) Then
.Cells(1, 7) = Controls(iFase).Name
Exit For
End If
Next
For Each iEntrega In Entregas
If Controls(iEntrega) Then
.Cells(1, 5) = Controls(iEntrega).Name
Exit For
End If
Next
For Each iTurno In TurnoS
If Controls(iTurno) Then
.Cells(1, 17) = Controls(iTurno).Name
Exit For
End If
Next
ws1.Range(.Cells(1, 9), .Cells(1, 15)).ClearContents
If Textbox3 <> "" Then .Cells(1, 9) = 0 + Textbox3 ' Desv 01
If TextBox4 <> "" Then .Cells(1, 10) = 0 + TextBox4 ' Desv 02
If TextBox5 <> "" Then .Cells(1, 11) = 0 + TextBox5 ' Desv 03
If TextBox6 <> "" Then .Cells(1, 12) = 0 + TextBox6 'Desv 04
If TextBox7 <> "" Then .Cells(1, 13) = 0 + TextBox7 'Desv 05
If Devuelto.Value = True Then .Cells(1, 14) = "1" 'Accion devolucion
If RNC.Value = True Then .Cells(1, 15) = "1" 'Accion RNC
If CommandButton2.Enabled = True Then .Cells(1, 26) = "1"
End With
End Sub
Private Sub Limpio_El_Formulario()
Dim i%, iFase, iEntrega, iTurno
ListBox1.RowSource = ""
For i = 2 To 15: Controls("Textbox" & i) = "": Next
For Each iFase In FaseS
Controls(iFase).Value = False
Next
For Each iEntrega In Entregas
Controls(iEntrega).Value = False
Next
For Each iTurno In TurnoS
Controls(iTurno).Value = False
Next
Devuelto = False
RNC = False
ComboBox1.ListIndex = -1
TextBox8 = Date
TextBox9 = Format(Time, "hh:mm:ss am/pm")
TextBox15 = Date
TextBox15.Enabled = False
TextBox14 = Format(Time, "hh:mm:ss am/pm")
TextBox14.Enabled = False
TextBox12 = Date
TextBox12.Enabled = False
TextBox13 = Format(Time, "hh:mm:ss am/pm")
TextBox13.Enabled = False
ToggleButton1.Value = False
TextBox10 = Date
TextBox10.Enabled = False
TextBox11 = Format(Time, "hh:mm:ss am/pm")
TextBox11.Enabled = False
ToggleButton2.Value = False
End Sub
Private Sub CommandButton5_Click()
'=======
'LIMPIAR
'=======
Limpio_El_Formulario
TextBox1.Value = ""
End Sub
Private Sub Devuelto_Click()
If Devuelto.Value = True Then
TextBox15.Enabled = True
Else: TextBox15.Enabled = False
End If
If Devuelto.Value = True Then
TextBox14.Enabled = True
Else: TextBox14.Enabled = False
End If
End SubGracias pero ¿como lo adapto a este código que es el que tengo para agregar y modificar datos desde un userform con listbox? la idea es que al hacer click en guardar se grabe el usuario al hacer click en botón agregar ya esto lo hice y faltaría al hacer click en modificar se ejecute el codigo que me esta explicando usted.
Del mismo modo en que pasas cada dato 'modificado' debes guardar en su columna el username.
Por ejemplo, si fuese la col J:
.Cells(1, 10) = .Cells(1, 10) & Application. Username
** Veo que en tu macro pasas otra información a partir de col 9 hasta la 15... seguramente entonces el usuario va en otra col... ajusta el nro 10 por el que corresponda.
Sdos!
Perfecto lo probé en el botón agregar y funciona pero como lo condiciono a que solo ocurra con el evento click del botón modificar
Private Sub CommandButton3_Click() '--------- 'Modificar '--------- With ListBox1 Pasar_a_la_hoja 0 + .List(.ListIndex, 0) End With CommandButton1_Click End Sub
¿Y por qué lo has probado en el botón Agregar si me pediste la instrucción para el botón Modificar y así te la envié?
Private Sub Pasar_a_la_hoja(LR&)
Dim iFase
Dim iEntrega
Dim iAccion
Dim iTurno
With ws1.Cells(LR, "a")
.Value = .Row
.Cells(1, 2) = TextBox1 ' Lote
.Cells(1, 3) = CDate(TextBox8) ' Fecha
.Cells(1, 4) = TextBox9 ' Hora
.Cells(1, 8) = Environ("Username") 'Firma de usuario .... si esta es la col ver (*)(*) reemplazar la última instrucción por esta otra:
.Cells(1, 8) = .Cells(1, 8) & " " & Application. Username
Si no deseas el espacio lo quitas.
Sdos!
- Compartir respuesta