Como hacer para insertar datos en dos hojas al mismo tiempo de un mismo libro mediante formulario

"para Dante Amor"

No sé si se pueda... Estoy tratando de hacer un formato de Cotización en Excel y VB, para esto tengo un libro con 3 hojas, "Cotización", "Clientes" y "Materiales", con un formulario hago que se inserten nuevos Clientes en la BD "Clientes", pero no se que agregarle al código del formulario para que esos mismos datos al momento de hacer clic en el boton Agregar se inserten al mismo tiempo en los campos requeridos en la hoja "Cotización".

Este es el código que tengo que solo hace que se inserten datos en la BD "Clientes" y no sé qué agregarle para que haga lo otro que requiero, (En todo caso si es que se pueda hacer que con el mismo formulario los datos se inserten en la "Cotización").

Private Sub CommandButton1_Click()

Dim TransRowRng As Range
Set TransRowRng = ThisWorkbook.Worksheets("Clientes").Cells(1, 1).CurrentRegion
NewRow = TransRowRng.Rows.Count + 1
With ThisWorkbook.Worksheets("Clientes")
.Cells(NewRow, 1).Value = INSERTAR_USUARIO.TextBox1.Value
.Cells(NewRow, 2).Value = INSERTAR_USUARIO.TextBox2.Value
.Cells(NewRow, 3).Value = INSERTAR_USUARIO.TextBox3.Value
.Cells(NewRow, 4).Value = INSERTAR_USUARIO.TextBox4.Value
.Cells(NewRow, 5).Value = INSERTAR_USUARIO.TextBox5.Value
.Cells(NewRow, 6).Value = INSERTAR_USUARIO.TextBox6.Value
.Cells(NewRow, 7).Value = INSERTAR_USUARIO.TextBox7.Value
.Cells(NewRow, 8).Value = INSERTAR_USUARIO.TextBox8.Value
End With
'Limpiar cajas de texto
INSERTAR_USUARIO.TextBox1.Value = ""
INSERTAR_USUARIO.TextBox2.Value = ""
INSERTAR_USUARIO.TextBox3.Value = ""
INSERTAR_USUARIO.TextBox4.Value = ""
INSERTAR_USUARIO.TextBox5.Value = ""
INSERTAR_USUARIO.TextBox6.Value = ""
INSERTAR_USUARIO.TextBox7.Value = ""
INSERTAR_USUARIO.TextBox8.Value = ""

MsgBox "Datos insertados "
End Sub

Respuesta
1

H o l a: Te anexo el código actualizado, supongo que en la hoja cotización va en una celdas fijas, te puse unos ejemplos, cambia las celdas por tus celdas

No es necesario que pongas el nombre del userform, a menos que tengas varios userform activos

Private Sub CommandButton1_Click()
'Act.Por.Dante Amor
    Set h1 = Sheets("Clientes")
    Set h2 = Sheets("Cotización")
    'llenar cliente
    u = h1.Range("A" & Rows.Count).End(xlUp).Row + 1
    h1.Cells(u, 1).Value = TextBox1.Value
    h1.Cells(u, 2).Value = TextBox2.Value
    h1.Cells(u, 3).Value = TextBox3.Value
    h1.Cells(u, 4).Value = TextBox4.Value
    h1.Cells(u, 5).Value = TextBox5.Value
    h1.Cells(u, 6).Value = TextBox6.Value
    h1.Cells(u, 7).Value = TextBox7.Value
    h1.Cells(u, 8).Value = TextBox8.Value
    '
    'llenar cotización
    h2.Range("B3") = TextBox1.Value
    h2.Range("B4") = TextBox2.Value
    h2.Range("D3") = TextBox3.Value
    h2.Range("D4") = TextBox4.Value
    h2.Range("D5") = TextBox5.Value
    h2.Range("F3") = TextBox6.Value
    h2.Range("F4") = TextBox7.Value
    h2.Range("F5") = TextBox8.Value
    'Limpiar cajas de texto
    TextBox1.Value = ""
    TextBox2.Value = ""
    TextBox3.Value = ""
    TextBox4.Value = ""
    TextBox5.Value = ""
    TextBox6.Value = ""
    TextBox7.Value = ""
    TextBox8.Value = ""
    '
    MsgBox "Datos insertados "
End Sub

'S aludos. Dante Amor. Recuerda valorar la respuesta. G racias

Si tengo otros 2 formularios activos

Entonces pon el nombre

Private Sub CommandButton1_Click()
'Act.Por.Dante Amor
    Set h1 = Sheets("Clientes")
    Set h2 = Sheets("Cotización")
    'llenar cliente
    u = h1.Range("A" & Rows.Count).End(xlUp).Row + 1
    h1.Cells(u, 1).Value = INSERTAR_USUARIO.TextBox1.Value
    h1.Cells(u, 2).Value = INSERTAR_USUARIO.TextBox2.Value
    h1.Cells(u, 3).Value = INSERTAR_USUARIO.TextBox3.Value
    h1.Cells(u, 4).Value = INSERTAR_USUARIO.TextBox4.Value
    h1.Cells(u, 5).Value = INSERTAR_USUARIO.TextBox5.Value
    h1.Cells(u, 6).Value = INSERTAR_USUARIO.TextBox6.Value
    h1.Cells(u, 7).Value = INSERTAR_USUARIO.TextBox7.Value
    h1.Cells(u, 8).Value = INSERTAR_USUARIO.TextBox8.Value
    '
    'llenar cotización
    h2.Range("B3") = INSERTAR_USUARIO.TextBox1.Value
    h2.Range("B4") = INSERTAR_USUARIO.TextBox2.Value
    h2.Range("D3") = INSERTAR_USUARIO.TextBox3.Value
    h2.Range("D4") = INSERTAR_USUARIO.TextBox4.Value
    h2.Range("D5") = INSERTAR_USUARIO.TextBox5.Value
    h2.Range("F3") = INSERTAR_USUARIO.TextBox6.Value
    h2.Range("F4") = INSERTAR_USUARIO.TextBox7.Value
    h2.Range("F5") = INSERTAR_USUARIO.TextBox8.Value
    'Limpiar cajas de texto
    INSERTAR_USUARIO.TextBox1.Value = ""
    INSERTAR_USUARIO.TextBox2.Value = ""
    INSERTAR_USUARIO.TextBox3.Value = ""
    INSERTAR_USUARIO.TextBox4.Value = ""
    INSERTAR_USUARIO.TextBox5.Value = ""
    INSERTAR_USUARIO.TextBox6.Value = ""
    INSERTAR_USUARIO.TextBox7.Value = ""
    INSERTAR_USUARIO.TextBox8.Value = ""
    '
    MsgBox "Datos insertados "
End Sub

'S aludos. Dante Amor. Recuerda valorar la respuesta. G racias

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas