Ingresar datos con formulario a otro libro cerrado
Publicado por Samuel (2 intervenciones) el 14/02/2019 11:54:48
Buenos dias a la comunidad de expertos, tengo la siguiente macro y me gustaría saber como lo puedo hacer para que los datos se ingresen en otro libro de excel que se encuentra cerrado.
..................................................................................................................................................................................
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
Function instertarRegistro(noIdentidad As String, nombres As String, apellidos As String, email As String, Direccion As String) As String
Dim ultFila, filaRegistro, existe As Long
Dim confirmacionRegistro As String
confirmacionRegistro = "No"
ultFila = Range("B" & Rows.Count).End(xlUp).Row
'fila en la cual se ingresara el dato
If ultFila < 8 Then
filaRegistro = 8 'fila 8 se debe cambiar
Else
filaRegistro = ultFila + 1
End If
' donde realizara la conuslta y variable
existe = filaExisteRegistro(noIdentidad, "B8:B" & ultFila)
If existe > 0 Then
MsgBox "El numero de identificacion ya existe en la bbdd"
instertarRegistro = confirmacionRegistro
Exit Function ' de esta forma salir del proceso
End If
Reto40Excel.Cells(filaRegistro, 2) = noIdentidad
Reto40Excel.Cells(filaRegistro, 3) = nombres
Reto40Excel.Cells(filaRegistro, 4) = apellidos
Reto40Excel.Cells(filaRegistro, 5) = email
Reto40Excel.Cells(filaRegistro, 6) = Direccion
MsgBox "Regsitro OK "
confirmacionRegistro = "Ingresado"
instertarRegistro = confirmacionRegistro
End Function
Private Function filaExisteRegistro(noIdentificacion As String, rangoConsulta As String) As Long
Dim numeroFila As Long
numeroFila = 0
With Reto40Excel.Range(rangoConsulta)
Set c = .Find(noIdentificacion, LookIn:=xlValues)
If Not c Is Nothing Then
numeroFila = c.Row
End If
End With
filaExisteRegistro = numeroFila
ultFila = Range("B" & Rows.Count).End(xlUp).Row
End Function
Sub verFormulario() ' para ver el fomrmulario
frmIngresoDatos.Show
End Sub
Sub ConsultarRegistro()
Dim ultFila As Long
Dim rango As String
Dim filaRegistro As Long
Dim noIdentidad As String
Dim nombres As String
Dim apellidos As String
Dim email As String
Dim Direccion As String
ultFila = Range("B" & Rows.Count).End(xlUp).Row
rango = "B8:B" & ultFila
If Len(frmIngresoDatos.TextBox1) = 0 Then
MsgBox "Ingrese el NUmero de identificacion"
Exit Sub
End If
filaRegistro = filaExisteRegistro(frmIngresoDatos.TextBox1, rango)
If filaRegistro = 0 Then
MsgBox "El numero Ingresadeo No existe"
Exit Sub
End If
nombres = Reto40Excel.Cells(filaRegistro, 3)
apellidos = Reto40Excel.Cells(filaRegistro, 4)
email = Reto40Excel.Cells(filaRegistro, 5)
Direccion = Reto40Excel.Cells(filaRegistro, 6)
frmIngresoDatos.TextBox2 = nombres
frmIngresoDatos.TextBox3 = apellidos
frmIngresoDatos.TextBox4 = email
frmIngresoDatos.TextBox5 = Direccion
End Sub
..................................................................................................................................................................................
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
Private Sub Cmdconsultar_Click()
Call Módulo1.ConsultarRegistro
End Sub
Private Sub CommandButton1_Click()
Dim confirmacionRegistro As String
If Len(TextBox1) = 0 Or Len(TextBox2) = 0 Or Len(TextBox3) = 0 Or Len(TextBox4) = 0 Or Len(TextBox5) = 0 Then
MsgBox "Ingresar datos completos"
Exit Sub
End If
' para desiganr los textbox a las varibles de la funcion
confirmacionRegistro = Módulo1.instertarRegistro(TextBox1, TextBox2, TextBox3, TextBox4, TextBox5)
If confirmacionRegistro <> "NO" Then
TextBox1 = ""
TextBox2 = ""
TextBox3 = ""
TextBox4 = ""
TextBox5 = ""
End If
End Sub
Private Sub UserForm_Initialize()
Application.Visible = False
End Sub
'
Private Sub UserForm_Terminate()
Application.Visible = True
End Sub
Valora esta pregunta


0