cómo se mezclan 2 códigos de 2 hojas en una sola
Publicado por celia (437 intervenciones) el 13/12/2018 12:18:18
Hola de nuevo. Llevo horas intentando entender la lógica para unir el código de 2 archivos de excel en 1 solo y he intentado copiar el código VBA de 1 en el otro y no me funciona. Lo copié delante, detrás, le borré trozos que parecen repetidos por probar y solo consigo errores como este: Nombre ambiguo Worksheet.SelectionChange.
Copio aquí los 2 códigos por si alguien sabe qué falla o cómo unirlos porque este no es mi campo. Muchas gracias
Código 1:
Código 2:
Copio aquí los 2 códigos por si alguien sabe qué falla o cómo unirlos porque este no es mi campo. Muchas gracias
Código 1:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim Lin As Integer, Col As Integer
Col = Target.Column
Fil = Target.Row
If Col >= 65 And Col <= 77 And Fil >= 3 And Fil <= 15 Then
Cells(6, 13) = Target.Value
End If
If Col >= 65 And Col <= 77 And Fil >= 3 And Fil <= 15 Then
Cells(12, 13) = Target.Value
End If
If Col >= 18 And Col <= 30 And Fil >= 3 And Fil <= 15 Then
Cells(4, 13) = Target.Value
End If
If Col >= 18 And Col <= 30 And Fil >= 3 And Fil <= 15 Then
Cells(12, 13) = Target.Value
End If
End Sub
Código 2:
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
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim Fila_Destin As Long, f As Long, Texto As String, _
Colu_Destin As Long, c As Long
Dim Lin As Integer, Col As Integer
Col = Target.Column
Fil = Target.Row
If Col >= 65 And Col <= 77 And Fil >= 3 And Fil <= 15 Then Cells(6, 13) = Target.Value
If Col >= 65 And Col <= 77 And Fil >= 3 And Fil <= 15 Then Cells(12, 13) = Target.Value
If Col >= 18 And Col <= 30 And Fil >= 3 And Fil <= 15 Then Cells(6, 13) = Target.Value
If Col >= 18 And Col <= 30 And Fil >= 3 And Fil <= 15 Then Cells(12, 13) = Target.Value
' ---&---
If Col = 13 And Fil = 7 Then
Texto = Cells(7, "M")
Fila_Destin = 42
Colu_Destin = 4
For Fil = 42 To 580 Step 15
For Col = 37 To 134 Step 14
If Texto = Cells(Fil, Col) Then
For f = 0 To 12
For c = 0 To 12
Cells(f + Fila_Destin, c + Colu_Destin) = Cells(f + Fil, c + Col)
Next
Next
Exit Sub
End If
Next
Next
End If
End Sub
Valora esta pregunta
0