COMO DAR SALTO DE FILA AL AGREGAR DATOS DE UN FORM
Publicado por Adriam Jesus (1 intervención) el 26/06/2019 23:22:47
Hace poco estuve creando esta macro que utiliza cajas de texto de un Form creado.
Como verán son simples. Mi duda viene en base a un error al momento de agregar los datos a una tabla
de una hoja de excel. Necesito ayuda para saber como dar el salto de fila a la de abajo pues al agregar con esta
macro se sobreescribe los datos.
AQUI la macro:
Me ayudaría mucho si resuelvo esto. Llevo días intentándolo
Gracias.
Como verán son simples. Mi duda viene en base a un error al momento de agregar los datos a una tabla
de una hoja de excel. Necesito ayuda para saber como dar el salto de fila a la de abajo pues al agregar con esta
macro se sobreescribe los datos.
AQUI la macro:
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
Dim fila As Long
Dim duplicados As Boolean
'obteniendo fila disponible
fila = Application.WorksheetFunction.CountA(Range("A5:L307")) + 1
duplicados = False
'Validar si se han ingresado datos duplicados
For i = 1 To fila
If Cells(i, 1).Value = UserForm5.txtFec.Value Then
If Cells(i, 2).Value = UserForm5.txtFac.Value Then
If Cells(i, 3).Value = UserForm5.cboLleno.Value Then
If Cells(i, 4).Value = UserForm5.txtIni.Value Then
If Cells(i, 5).Value = UserForm5.txtFin.Value Then
If Cells(i, 7).Value = UserForm5.txtLitros.Value Then
If Cells(i, 8).Value = UserForm5.txtPrecio.Value Then
If Cells(i, 10).Value = UserForm5.cboTipoCom.Value Then
If Cells(i, 11).Value = UserForm5.cboTipoRut.Value Then
If Cells(i, 12).Value = UserForm5.txtObs.Value Then
'SE ENCONTRO DATOS DUPLICADOS
MsgBox "Datos duplicados en la fila " & i
duplicados = True
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
Next i
If Not duplicados Then
'Insertando los datos
Worksheets("MODELO").Range("A7").Value = UserForm5.txtFec.Value
Worksheets("MODELO").Range("B7").Value = UserForm5.txtFac.Value
Worksheets("MODELO").Range("C7").Value = UserForm5.cboLleno.Value
Worksheets("MODELO").Range("D7").Value = UserForm5.txtIni.Value
Worksheets("MODELO").Range("E7").Value = UserForm5.txtFin.Value
Worksheets("MODELO").Range("G7").Value = UserForm5.txtLitros.Value
Worksheets("MODELO").Range("H7").Value = UserForm5.txtPrecio.Value
Worksheets("MODELO").Range("J7").Value = UserForm5.cboTipoCom.Value
Worksheets("MODELO").Range("K7").Value = UserForm5.cboTipoRut.Value
Worksheets("MODELO").Range("L7").Value = UserForm5.txtObs.Value
'Limpiando cajas de texto
UserForm5.txtFec.Value = ""
UserForm5.txtFac.Value = ""
UserForm5.cboLleno.Value = ""
UserForm5.txtIni.Value = ""
UserForm5.txtFin.Value = ""
UserForm5.txtLitros.Value = ""
UserForm5.txtPrecio.Value = ""
UserForm5.cboTipoCom.Value = ""
UserForm5.cboTipoRut.Value = ""
UserForm5.txtObs.Value = ""
'Notificando
MsgBox "Datos insertados en la fila " & fila
End If
Me ayudaría mucho si resuelvo esto. Llevo días intentándolo
Gracias.
Valora esta pregunta
0