guardar datos al final de la fila
Publicado por nestor fernando (12 intervenciones) el 03/05/2020 19:42:45
Buen dia amigos, les agradezco por el apoyo, estoy tratando de modificar la siguiente macro de vba para excel, en donde pretendo poner valores en la ultima celda de una fila, y seguir añadiendo celdas a la misma fila, pues quiero utilizarla para un servicio técnico en donde se reciben aparatos y mientras se van arreglando se van necesitando repuestos, hasta el momento con esta macro he podido buscar el registro y modificarlo, si no se encuentra el registro se crea uno nuevo, pero no he logrado que me añada mas celdas al final de cada registro para la necesidad que tengo, muchas gracias por la ayuda
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
Public ubica As String
Public control As Integer
Public ColumnaLibre As Integer
Public filalibre As Integer
Private Sub CommandButton1_Click()
'ColumnaLibre = Sheets("hoja1").Range((Cells(ubica, 1)), Range((Cells(ubica, 1)), Cells(ubica, 1)).End(xlToRight)).Select
Sheets("Hoja1").Select
If control > 0 Then
'Actualizar Datos
Range(ubica).Value = TextBox1
Range(ubica).Offset(0, 1).Value = TextBox2
Range(ubica).Offset(0, 2).Value = Val(TextBox3)
Range(ubica).Offset(0, ColumnaLibre).Value = Me.TextBox4
control = 0
Else
'Crear nuevos datos
Cells(filalibre, 1).Value = TextBox1
Cells(filalibre, 2).Value = TextBox2
Cells(filalibre, 3).Value = Val(TextBox3)
Cells(filalibre, ColumnaLibre).Value = TextBox4
End If
TextBox1 = Empty
TextBox2 = Empty
TextBox3 = Empty
TextBox4 = Empty
TextBox1.SetFocus
End Sub
Private Sub CommandButton2_Click()
TextBox1 = Empty
TextBox2 = Empty
TextBox3 = Empty
TextBox4 = Empty
TextBox1.SetFocus
Sheets("Formularios").Select
End Sub
Private Sub CommandButton3_Click()
Unload UserForm1
Sheets("Formularios").Select
End Sub
Private Sub TextBox1_AfterUpdate()
Sheets("Hoja1").Select
filalibre = Range("A2").End(xlDown).Offset(1, 0).Row
ColumnaLibre = Range("a3:a1000000").End(xlToRight).Offset(1, 1).Column
'la variable filalibre guarda el nro. de la primer celda vacía.
control = 0
dato = TextBox1
rango = "A2:A" & filalibre
Set midato = ActiveSheet.Range(rango).Find(dato, LookIn:=xlValues, LookAt:=xlWhole)
If (midato) Is Nothing Then
MsgBox "No se encontraron los datos, se procede a crear uno nuevo"
Else
ubica = midato.Address(False, False)
TextBox2.Value = Range(ubica).Offset(0, 1).Value
TextBox3.Value = Range(ubica).Offset(0, 2).Value
control = 1
End If
Set midato = Nothing
End Sub
- actualizar-y-buscar.rar(24,9 KB)
Valora esta pregunta


0