Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.ScreenUpdating = False
'Application.EnableEvents = True
Application.EnableEvents = False
Dim Lin As Integer, col As Integer
Dim Fila_Destin As Long, f As Long, Texto As String, _
Colu_Destin As Long, c As Long
' --- Aqui asignas unos valores que mas adelate pierdes
col = Target.Column ': Application.EnableEvents = False
Fil = Target.Row
If Target.Cells.Count > 1 Then Exit Sub
If col = 4 And Fil = 7 Then
Fila_Destin = 57
Colu_Destin = 37: Texto = Cells(7, "D")
If Range("d7").Value <> Range("AK57").Value Then
For Fil = 42 To 42 Step 15
For col = 37 To 384 Step 13
If Texto = Cells(Fil, col) Then
Range(Cells(Fil, col), Cells((Fil + 13), (col + 12))).Select
Selection.Copy
Range("ak57").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Application.EnableEvents = True
'GoTo SalNOMBRE1
Fil = 42
Col = 384 ' --- Fuerzo el Exit For en los dos
End If
Next
Next
End If
End If
'SalNOMBRE1:
If Range("e7").Value <> Range("AY57").Value Then
' WARNING --- Las variables Col y Fil si se ejecuto el FOR anterior ya no
' tienen los valores capturados anteriormente
' --- Aqui asignas nuevos valores
col = Target.Column
Fil = Target.Row
If col = 5 And Fil = 7 Then
Fila_Destin = 57
Colu_Destin = 51: Texto = Cells(7, "E")
For Fil = 42 To 42 Step 15
For col = 37 To 384 Step 13
If Texto = Cells(Fil, col) Then
Range(Cells(Fil, col), Cells((Fil + 13), (col + 12))).Select
Selection.Copy
Range("AY57").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Application.EnableEvents = True
'GoTo SalNOMBRE2
Fil = 42
Col = 384 ' --- Fuerzo el Exit For en los dos
End If
Next
Next
End If
End If
'SalNOMBRE2:
If Range("D8").Value <> Range("AK71").Value Then
' WARNING --- Las variables Col y Fil si se ejecuto el FOR anterior ya no
' tienen los valores capturados anteriormente
' --- Aqui asignas nuevos valores
col = Target.Column
Fil = Target.Row
If col = 4 And Fil = 8 Then
Fila_Destin = 71
Colu_Destin = 37: Texto = Cells(8, "D")
For Fil = 42 To 42 Step 15
For col = 37 To 384 Step 13
If Texto = Cells(Fil, col) Then
Range(Cells(Fil, col), Cells((Fil + 13), (col + 12))).Select
Selection.Copy
Range("AK71").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Application.EnableEvents = True
'GoTo SalNOMBR3
Fil = 42
Col = 384 ' --- Fuerzo el Exit For en los dos
End If
Next
Next
End If
End If
'SalNOMBRE3:
If Range("E8").Value <> Range("AY71").Value Then
' WARNING --- Las variables Col y Fil si se ejecuto el FOR anterior ya no
' tienen los valores capturados anteriormente
' --- Aqui asignas nuevos valores
col = Target.Column
Fil = Target.Row
If col = 5 And Fil = 8 Then
Fila_Destin = 71
Colu_Destin = 51: Texto = Cells(8, "E")
For Fil = 42 To 42 Step 15
For col = 37 To 384 Step 13
If Texto = Cells(Fil, col) Then
Range(Cells(Fil, col), Cells((Fil + 13), (col + 12))).Select
Selection.Copy
Range("AY71").Select
ActiveSheet.Paste
'Application.CutCopyMode = False
'Application.EnableEvents = True
Exit Sub
End If
Next
Next
End If
'Application.EnableEvents = True
End If
' Exit Sub
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub