Pasar datos de formularios vba excel a hoja y celda especifica

Quisiera pasar datos de un formulario vba excel a una hoja y celda especifica, lo tengo del siguiente modo:

Private Sub btn1_Click()
ActiveCell.Value = Txt1.Text
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = txt2.Text
ActiveCell.Offset(0, 2).Select
ActiveCell.Value = txt3.Text
ActiveCell.Offset(0, 3).Select
ActiveCell.Value = lst1.Text
ActiveCell.Offset(0, 4).Select
ActiveCell.Value = txt4.Text
ActiveCell.Offset(0, 5).Select
ActiveCell.Value = txt5.Text
ActiveCell.Offset(0, 6).Select
ActiveCell.Value = txt6.Text
ActiveCell.Offset(1, -7).Select
ActiveWorkbook.Save
Txt1.Text = ""
txt2.Text = ""
txt3.Text = ""
txt4.Text = ""
txt5.Text = ""
txt6.Text = ""
Txt1.SetFocus
End Sub

De esto modo solo me copia en la hoja abierta en ese momento y copia donde quiere, deseo como redacte anteriormente, indicarle donde copiar y que celda, además de ello que luego en la siguiente entrada de formulario siga corriendo hacía abajo (guardando la información).

1 Respuesta

Respuesta
1

Te anexo el código actualizado.

Cambia "Hoja1" por el nombre de tu hoja

Cambia "A", "B", "C", "D", "E", "F" por las columnas donde quieras guardar cada txt

Private Sub btn1_Click()
    Set h = Sheets("Hoja1")  'establecer el nombre de hoja
    u = h.Range("A" & Rows.Count).End(xlUp).Row + 1 'fila vacía siguiente
    If Txt1.Text = "" Then
        MsgBox "Debes introducir un datos en le text1", vbCritical
        Txt1.SetFocus
        Exit Sub
    End If
    '
    h.Cells(u, "A").Value = Txt1.Text
    h.Cells(u, "B").Value = Txt2.Text
    h.Cells(u, "C").Value = Txt3.Text
    h.Cells(u, "D").Value = Txt4.Text
    h.Cells(u, "E").Value = Txt5.Text
    h.Cells(u, "F").Value = Txt6.Text
    ThisWorkbook.Save
    Txt1.Text = ""
    Txt2.Text = ""
    Txt3.Text = ""
    Txt4.Text = ""
    Txt5.Text = ""
    Txt6.Text = ""
    Txt1.SetFocus
End Sub

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

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas