Macro: copiar datos de formulario a hoja seleccionada
Necesito que la macro copie los datos ingresados en el formulario en la hoja que selecione desde un combobox, hasta ahí lo hace... Pero repite la fila donde copia (osea, lo hace en una sola). Y de ser posible, ¿se le puede agregar la opción de agregar un link en uno de los textbox?
El cód. Que tengo es:
Option Explicit
Private Sub CommandButton1_Click()
Dim NombreHoja As String
Dim HojaDestino As Range
Dim NuevaFila As Integer
NombreHoja = Me.ComboBox1.Value
Set HojaDestino = ThisWorkbook.Sheets(NombreHoja).Range("A7").CurrentRegion
NuevaFila = HojaDestino.Rows.Count + 1
With ThisWorkbook.Sheets(NombreHoja)
.Cells(NuevaFila, 1).Value = Date
.Cells(NuevaFila, 2).Value = Me.TextBox1.Value
.Cells(NuevaFila, 3).Value = Me.TextBox2.Value
.Cells(NuevaFila, 4).Value = Me.ComboBox1.Value
.Cells(NuevaFila, 5).Value = Me.TextBox3.Value
End With
MsgBox "Alta exitosa.", vbInformation, "EXCELeINFO"
Unload Me
End Sub
Private Sub CommandButton2_Click()
Unload Me
End Sub
'Al iniciar el formulario
Private Sub UserForm_Initialize()
Dim intHojas As Integer
Dim i As Integer
intHojas = ThisWorkbook.Sheets.Count
For i = 2 To intHojas
Me.ComboBox1.AddItem ThisWorkbook.Sheets(i).Name
Next i
End Sub
1 respuesta
Respuesta de Elsa Matilde
1

