Excel - Macro sobre escribe registros

 
Vista:
sin imagen de perfil
Val: 9
Ha aumentado su posición en 5 puestos en Excel (en relación al último mes)
Gráfica de Excel

Macro sobre escribe registros

Publicado por Juan F (42 intervenciones) el 10/11/2016 07:52:01
buenas horas a todos, el tema es de que necesito pegar con un macro datos de 3 hojas y de columnas diferentes en una sola hoja de excel (RESUMEN)

Los datos se tienen que pegar en la hoja RESUMEN uno debajo del otro, sin que estos se sobre escriban.

He elaborado este macro pero no logro solucionar el problema de que se sobreescribe:

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
Sub Copiar_Filas()
 
Sheets("01 MUEBLES").Activate
Sheets("02 TRANSPORTES").Activate
Sheets("06 EQUIPOS INFORMATICOS").Activate
 
j = 2
 
    For i = 2 To 10205
        'compruebo que el valor es mayor que 0
        If Cells(i, "B").Value > 0 Then
            'copio la fila entera y la pego
            Range(Cells(i, "B"), Cells(i, "B")).Copy Destination:=Sheets("RESUMEN").Cells(j, "B")
            Range(Cells(i, "D"), Cells(i, "D")).Copy Destination:=Sheets("RESUMEN").Cells(j, "D")
            Range(Cells(i, "E"), Cells(i, "E")).Copy Destination:=Sheets("RESUMEN").Cells(j, "E")
            Range(Cells(i, "F"), Cells(i, "F")).Copy Destination:=Sheets("RESUMEN").Cells(j, "F")
            Range(Cells(i, "G"), Cells(i, "G")).Copy Destination:=Sheets("RESUMEN").Cells(j, "G")
            Range(Cells(i, "H"), Cells(i, "H")).Copy Destination:=Sheets("RESUMEN").Cells(j, "H")
            Range(Cells(i, "I"), Cells(i, "I")).Copy Destination:=Sheets("RESUMEN").Cells(j, "I")
            Range(Cells(i, "J"), Cells(i, "J")).Copy Destination:=Sheets("RESUMEN").Cells(j, "J")
            Range(Cells(i, "K"), Cells(i, "K")).Copy Destination:=Sheets("RESUMEN").Cells(j, "K")
            Range(Cells(i, "O"), Cells(i, "L")).Copy Destination:=Sheets("RESUMEN").Cells(j, "L")
 
            j = j + 1
 
    End If
Next
 
End Sub

Por favor necesito su ayuda, gracias
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil
Val: 83
Ha aumentado su posición en 2 puestos en Excel (en relación al último mes)
Gráfica de Excel

Macro sobre escribe registros

Publicado por GMG (119 intervenciones) el 10/11/2016 17:20:36
Hola Juan F;

Para empezar, has de tener presente que las instrucciones:

1
2
3
Sheets("01 MUEBLES").Activate
Sheets("02 TRANSPORTES").Activate
Sheets("06 EQUIPOS INFORMATICOS").Activate

Te activan la hoja, pero al poner las tres instrucciones consecutivas las dos primeras no hacen nada, es decir únicamente miras en la hoja "06 EQUIPOS INFORMATICOS", ya que es la que queda activa finalmente antes de entrar en el bucle for.

Saludos
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil
Val: 9
Ha aumentado su posición en 5 puestos en Excel (en relación al último mes)
Gráfica de Excel

Macro sobre escribe registros

Publicado por Juan Francisco (42 intervenciones) el 11/11/2016 01:08:01
Como poder hacerlo, si pudieras con un modelo ejemplo, gracias
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Antoni Masana
Val: 4.908
Oro
Ha mantenido su posición en Excel (en relación al último mes)
Gráfica de Excel

Macro sobre escribe registros

Publicado por Antoni Masana (2464 intervenciones) el 11/11/2016 06:31:34
Benas Juan Francisco,

Sube un fichero de ejemplo y sobre eso te podremos ayudar. Con la Macro que has puesto y sin comentarios de lo que deseas hacer es difícil ayudarte.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Manuel
Val: 108
Ha mantenido su posición en Excel (en relación al último mes)
Gráfica de Excel

Macro sobre escribe registros

Publicado por Manuel (32 intervenciones) el 11/11/2016 11:47:23
Si ya lo tienes echo casi todo... simplemente en lugar de intentar acceder a las 3 al mismo tiempo y que así solo accedes a la última que activaste, pues haz lo mismo pero de hoja en hoja y así recorres las 3. A mayores ten en cuenta que en j tienes que guardar en donde terminaste de copiar la hoja anterior. Te lo voy a hacer a lo básico usando tu código:

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
Sub Copiar_Filas()
 
Sheets("01 MUEBLES").Activate
 
j = 2
 
    For i = 2 To 10205
        'compruebo que el valor es mayor que 0
 
        If Cells(i, "B").Value > 0 Then
            'copio la fila entera y la pego
 
            Range(Cells(i, "B"), Cells(i, "B")).Copy Destination:=Sheets("RESUMEN").Cells(j, "B")
            Range(Cells(i, "D"), Cells(i, "D")).Copy Destination:=Sheets("RESUMEN").Cells(j, "D")
            Range(Cells(i, "E"), Cells(i, "E")).Copy Destination:=Sheets("RESUMEN").Cells(j, "E")
            Range(Cells(i, "F"), Cells(i, "F")).Copy Destination:=Sheets("RESUMEN").Cells(j, "F")
            Range(Cells(i, "G"), Cells(i, "G")).Copy Destination:=Sheets("RESUMEN").Cells(j, "G")
            Range(Cells(i, "H"), Cells(i, "H")).Copy Destination:=Sheets("RESUMEN").Cells(j, "H")
            Range(Cells(i, "I"), Cells(i, "I")).Copy Destination:=Sheets("RESUMEN").Cells(j, "I")
            Range(Cells(i, "J"), Cells(i, "J")).Copy Destination:=Sheets("RESUMEN").Cells(j, "J")
            Range(Cells(i, "K"), Cells(i, "K")).Copy Destination:=Sheets("RESUMEN").Cells(j, "K")
            Range(Cells(i, "O"), Cells(i, "L")).Copy Destination:=Sheets("RESUMEN").Cells(j, "L")
 
            j = j + 1
 
    End If
Next
 
Sheets("02 TRANSPORTES").Activate
 
 
    For i = 2 To 10205
        'compruebo que el valor es mayor que 0
 
        If Cells(i, "B").Value > 0 Then
            'copio la fila entera y la pego
 
            Range(Cells(i, "B"), Cells(i, "B")).Copy Destination:=Sheets("RESUMEN").Cells(j, "B")
            Range(Cells(i, "D"), Cells(i, "D")).Copy Destination:=Sheets("RESUMEN").Cells(j, "D")
            Range(Cells(i, "E"), Cells(i, "E")).Copy Destination:=Sheets("RESUMEN").Cells(j, "E")
            Range(Cells(i, "F"), Cells(i, "F")).Copy Destination:=Sheets("RESUMEN").Cells(j, "F")
            Range(Cells(i, "G"), Cells(i, "G")).Copy Destination:=Sheets("RESUMEN").Cells(j, "G")
            Range(Cells(i, "H"), Cells(i, "H")).Copy Destination:=Sheets("RESUMEN").Cells(j, "H")
            Range(Cells(i, "I"), Cells(i, "I")).Copy Destination:=Sheets("RESUMEN").Cells(j, "I")
            Range(Cells(i, "J"), Cells(i, "J")).Copy Destination:=Sheets("RESUMEN").Cells(j, "J")
            Range(Cells(i, "K"), Cells(i, "K")).Copy Destination:=Sheets("RESUMEN").Cells(j, "K")
            Range(Cells(i, "O"), Cells(i, "L")).Copy Destination:=Sheets("RESUMEN").Cells(j, "L")
 
            j = j + 1
 
    End If
Next
 
Sheets("06 EQUIPOS INFORMATICOS").Activate
 
    For i = 2 To 10205
        'compruebo que el valor es mayor que 0
 
        If Cells(i, "B").Value > 0 Then
            'copio la fila entera y la pego
 
            Range(Cells(i, "B"), Cells(i, "B")).Copy Destination:=Sheets("RESUMEN").Cells(j, "B")
            Range(Cells(i, "D"), Cells(i, "D")).Copy Destination:=Sheets("RESUMEN").Cells(j, "D")
            Range(Cells(i, "E"), Cells(i, "E")).Copy Destination:=Sheets("RESUMEN").Cells(j, "E")
            Range(Cells(i, "F"), Cells(i, "F")).Copy Destination:=Sheets("RESUMEN").Cells(j, "F")
            Range(Cells(i, "G"), Cells(i, "G")).Copy Destination:=Sheets("RESUMEN").Cells(j, "G")
            Range(Cells(i, "H"), Cells(i, "H")).Copy Destination:=Sheets("RESUMEN").Cells(j, "H")
            Range(Cells(i, "I"), Cells(i, "I")).Copy Destination:=Sheets("RESUMEN").Cells(j, "I")
            Range(Cells(i, "J"), Cells(i, "J")).Copy Destination:=Sheets("RESUMEN").Cells(j, "J")
            Range(Cells(i, "K"), Cells(i, "K")).Copy Destination:=Sheets("RESUMEN").Cells(j, "K")
            Range(Cells(i, "O"), Cells(i, "L")).Copy Destination:=Sheets("RESUMEN").Cells(j, "L")
 
            j = j + 1
 
    End If
Next
 
 
End Sub


Hasta luego
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil
Val: 9
Ha aumentado su posición en 5 puestos en Excel (en relación al último mes)
Gráfica de Excel

Macro sobre escribe registros

Publicado por JUAN F (42 intervenciones) el 11/11/2016 14:48:45
Ok Manuel gracias, estaba programando mal al intentar cambiar la variable For i = 2 To 10205 por For ii = 2 To 10205 y For iii = 2 To 10205, valga tu aclaración me di cuenta de mi error

Gracias nuevamente
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Manuel
Val: 108
Ha mantenido su posición en Excel (en relación al último mes)
Gráfica de Excel

Macro sobre escribe registros

Publicado por Manuel (32 intervenciones) el 12/11/2016 11:52:45
Un placer, me alegra haberte sido útil.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar