En mis indicaciones puse esto:
Sigue las Instrucciones para poner la macro en los eventos de worksheet
- Abre tu libro de excel
- Para abrir Vba-macros y poder pegar la macro, Presiona Alt + F11
- Del lado izquierdo dice: VBAProject, abajo dale doble click a worksheet(tu hoja)
- En el panel del lado derecho copia la macro
Tienes que adaptar mi código para que funcione en el userform.
Te anexo las adecuaciones
Private Sub CommandButton4_Click()
'Ingresar datos
pedido = TextBox1.Value
If pedido = "" Then
MsgBox "Debes capturar un número de pedido"
TextBox1.SetFocus
Exit Sub
End If
If IsNumeric(pedido) Then pedido = Val(pedido)
Set h = Sheets("Report")
Set r = h.Columns("A")
Set b = r.Find(pedido, LookAt:=xlWhole)
If Not b Is Nothing Then
Celda = b.Address
Do
'detalle
If h.Cells(b.Row, "B") = "" Then
h.Cells(b.Row, "B") = ComboBox4.Value 'Columna B Courier
h.Cells(b.Row, "C") = ComboBox2.Value 'Columna C Placa
h.Cells(b.Row, "D") = TextBox7.Value 'Columna D Nombre del Transportista
h.Cells(b.Row, "E") = TextBox1.Value 'Columna E N° de Pedido
h.Cells(b.Row, "F") = TextBox5.Value 'Columna E GR Hija
h.Cells(b.Row, "I") = Now 'Fecha y hora
TextBox2 = Sheets("Datos").Range("E2")
Else
MsgBox "Pedido ya existe"
TextBox1.Value = ""
TextBox1.Value = ""
TextBox5.Value = ""
TextBox1.SetFocus
Exit Sub
End If
Set b = r.FindNext(b)
Loop While Not b Is Nothing And b.Address <> Celda
TextBox1.Value = ""
TextBox1.Value = ""
TextBox5.Value = ""
TextBox1.SetFocus
Else
MsgBox "El pedido no existe"
TextBox1.Value = ""
TextBox1.Value = ""
TextBox5.Value = ""
TextBox1.SetFocus
End If
End Sub
IMPORTANTE! : tienes que poner en la columna I el formato de fecha y hora
Prueba y me comentas.
.
.