Automatizar un valor preestablecido pero dinámico a un textbox. (Macro Excel)

expert@s!! Hoy me encuentro con la siguiente duda; tengo un USERFORM1 donde solicito 5 valores (DATO1, DATO2, DATO3, FECHA1 y NUMERO1), con un boton que:

1- Registra todos esos datos en HOJA1.

2- Crea un COD1 (Numerico) y

3- Abre USERFORM2 donde tengo 6 textbox.

En USERFORM2 quiero que al introducir el COD1 en TEXBOX1 se arrastren (DATO1, DATO2, DATO3, FECHA1 y NUMERO1) al resto de textboxs y que queden bloqueados para ser modificados los datos.

Gracias de antemano expert@s!!!

1 respuesta

Respuesta
1

Para qué es le Userform2, ¿para consultar?

Después de crear el COD1, ¿cierras el Userform1?

Puedes poner una imagen de la hoja de excel donde estás almacenado: COD1, DATO1, DATO2, DATO3, FECHA1 y NUMERO1

El userform2 al igual que userform1 es para registrar información (en ambas userforms mediante textboxs), solo que en la userform2 además de la info de COD1, DATO1, DATO2, DATO3, FECHA1 y NUMERO1 que se mostraría bloqueada en los TEXBOX1, 2,3,4,5,6 tendría otros TEXTBOXS que si estarían libres de ingresar información.

Al crear el cod, Si, se cierra la USEREFORM1.

La hoja donde se almacena lo ingresado en la USEREFORM1. Tendría esta forma:

Pon lo siguiente en un commanbutton en tu userform2

Private Sub CommandButton1_Click()
'Buscar COD1
    If TextBox1.Value = "" Then
        MsgBox "Introduce un COD1"
        TextBox1.SetFocus
        Exit Sub
    End If
    '
    TextBox2.Value = ""
    TextBox3.Value = ""
    TextBox4.Value = ""
    TextBox5.Value = ""
    TextBox6.Value = ""
    '
    Set h = Sheets("Hoja2")
    Set b = h.Columns("A").Find(TextBox1.Value, lookat:=xlWhole)
    If Not b Is Nothing Then
        TextBox2.Value = h.Cells(b.Row, "B").Value
        TextBox3.Value = h.Cells(b.Row, "C").Value
        TextBox4.Value = h.Cells(b.Row, "D").Value
        TextBox5.Value = h.Cells(b.Row, "E").Value
        TextBox6.Value = h.Cells(b.Row, "F").Value
    Else
        MsgBox "No existe el COD1", vbExclamation
    End If
End Sub


'.[Sal u dos. Dante Amor. No olvides valorar la respuesta. 
'.[Avísame cualquier duda

¡Gracias! genioooo Dante Amor 

Dante Amor amigo ayúdame con esto que me esta volviendo loca; (necesito agregar una condición más te la escribo al final)...

Private Sub CommandButton1_Click()
Application.ScreenUpdating = False

Dim COLUM As Range
Set COLUM = ThisWorkbook.Sheets("STOCK").Range("B6:B5000")
Set BUSCA = COLUM.Find(TextBox1.Value, lookat:=xlWhole)


'***VALIDACIONES
'1-SI EL COD ES INVALIDO O ESTA VACIO
If TextBox1.Value = "" Then
MsgBox "Introduce el numero de orden."
TextBox1.SetFocus
Exit Sub
ElseIf Not IsNumeric(TextBox1.Value) Then
MsgBox "Orden invalida."
TextBox1.Value = ""
ComboBox1.Value = ""
TextBox1.SetFocus
Exit Sub
'2-Valida que halla observacion (opciones listadas en el combobox)
ElseIf ComboBox1.Value = "" Then
MsgBox "Seleccione una observacion."
Exit Sub

'***RESPUESTAS POSITIVAS (si BUSCA encuentra el valor)
'1-Copia y pega la fecha
ElseIf Not BUSCA Is Nothing Then
ThisWorkbook.Sheets("STOCK").Range("E1").Copy
BUSCA.Select
ActiveCell.Offset(0, 3).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
'2-CAMBIO EL ESTATUS DE LA CORDEN POR INGRESADO MOVIENDOLO DE COLUMNA
ActiveCell.Select
ActiveCell.Offset(0, -2).Select
ActiveCell.Copy
ActiveCell.Offset(0, 1).Select
ActiveCell.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=True, Transpose:=True
ActiveCell.Offset(0, -1).ClearContents
'3-INGRESO  OBSERVACIONES
ActiveCell.Offset(0, 3).Value = Me.ComboBox1.Value
Call SOLICITUD_LOGISTICA ´(es un subcomando que envia un correo)
Exit Sub


'***NEGATIVAS
'1-SI NO LO ENCUENTRA
Else
MsgBox "La orden no existe."
TextBox1.Value = ""
ComboBox1.Value = ""
Exit Sub
End If

AHORA TODO LO QUE ESCRIBO ABAJO NO SE COMO INCORPORARLO, YA HE INTENTADO EN TODOS LADOS (QUIZÁS SEA QUE ESTOY ERRANDO EN LA FORMA DEL CÓDIGO) Lo que quiero hacer es que cuando BUSCA encuentre el valor revise la columna siguiente de la derecha y si esta vacía me de el mensaje de abajo y si no esta vacía que haga lo que dice arriba (ElseIf Not BUSCA Is Nothing Then)

help please!! 


'Set DDD = ActiveCell.Offset(0, 1)
' BUSCA.Select
' If DDD = "" Then
' MsgBox "La Orden ya fue ingresada anteriormente."
' TextBox1.Value = ""
' ComboBox1.Value = ""
' Exit Sub
' End If
End Sub

Con gusto te ayudo con todas tus peticiones. Crea una nueva pregunta. Ahí explicas con ejemplos lo que necesitas.

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas