Ejecutar macros en un determinado rango

Hola amig@s expertos tengo una duda no se si exista alguna manera de ejecutar unos macros en cada linea de un determinado rango
es decir la macro se ejecuta en la linea a12 y la misma se debe ejecutar en la a13
aquí les dejo como lo tengo programado, pero si lo programo de linea en linea son muchos ya que son 60 linea
qui les dejo como lo ejecuto en 3 linea, pero debo de colocarlos en 60 me pueden ayudar de antemano muchas gracias
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$B$12" Then ' Linea 1 Código de Barras
If Range("B12") = "" Then
Call borrarfila
Exit Sub
End If
Call buscabarra
If Range("P11") = 1 Then ' el rango P11 es fijo nunca cambia
Selection.ClearContents
Exit Sub
End If
End If
If Target.Address = "$C$12" Then ' Linea 1 busca id
If Range("C12") = "" Then
Call borrarfila
Exit Sub
End If
Call buscaid
If Range("P11") = 1 Then ' el rango P11 es fijo nunca cambia
Selection.ClearContents
Exit Sub
End If
End If
If Target.Address = "$D$12" Then ' Linea 1 para Calcular el importe neto
If Range("C12") = "" Then
Range("C12").Select
Selection.ClearContents
Exit Sub
End If
If Range("P12") = 1 Then
If Range("D12") = 0 Then
Range("D12") = 1
End If
ActiveSheet.Unprotect
Call multiplicación
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, AllowFormattingCells:=True
End If
End If
If Target.Address = "$J$12" Then ' Linea 1 Para Calcular Promociones
If Range("P12") = 1 Then
If Range("J12") = "" Then
Call restaurarprecio
Exit Sub
End If
End If
If Range("J12") > Range("I12") Then
Call promocion02
Exit Sub
End If
If Range("J12") = Range("I12") Then
Exit Sub
End If
Call promocion01
End If
If Target.Address = "$B$13" Then ' Linea 2 Código de Barras
If Range("B13") = "" Then
Call borrarfila
Exit Sub
End If
Call buscabarra
If Range("P11") = 1 Then ' el rango P11 es fijo
Selection.ClearContents
Exit Sub
End If
End If
If Target.Address = "$C$13" Then ' Linea 2 busca id
If Range("C13") = "" Then
Call borrarfila
Exit Sub
End If
Call buscaid
If Range("P11") = 1 Then el rango P11 es fijo
Selection.ClearContents
Exit Sub
End If
End If
If Target.Address = "$D$13" Then ' Linea 2 para Calcular el importe neto
If Range("C13") = "" Then
Range("C13").Select
Selection.ClearContents
Exit Sub
End If
If Range("P13") = 1 Then
If Range("D13") = 0 Then
Range("D13") = 1
End If
ActiveSheet.Unprotect
Call multiplicación
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, AllowFormattingCells:=True
End If
End If
If Target.Address = "$J$13" Then ' Linea 2 Para Calcular Promociones
If Range("P13") = 1 Then
If Range("J13") = "" Then
Call restaurarprecio
Exit Sub
End If
End If
If Range("J13") > Range("I13") Then
Call promocion02
Exit Sub
End If
If Range("J13") = Range("I13") Then
Exit Sub
End If
Call promocion01
End If
If Target.Address = "$B$14" Then ' Linea 3 Código de Barras
If Range("B14") = "" Then
Call borrarfila
Exit Sub
End If
Call buscabarra
If Range("P11") = 1 Then ' el rango P11 es fijo
Selection.ClearContents
Exit Sub
End If
End If
If Target.Address = "$C$14" Then ' Linea 3 busca id
If Range("C14") = "" Then
Call borrarfila
Exit Sub
End If
Call buscaid
If Range("P11") = 1 Then ' el rango P11 es fijo
Selection.ClearContents
Exit Sub
End If
End If
If Target.Address = "$D$14" Then ' Linea 3 para Calcular el importe neto
If Range("C14") = "" Then
Range("C14").Select
Selection.ClearContents
Exit Sub
End If
If Range("P14") = 1 Then
If Range("D14") = 0 Then
Range("D14") = 1
End If
ActiveSheet.Unprotect
Call multiplicación
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, AllowFormattingCells:=True
End If
End If
If Target.Address = "$J$14" Then ' Linea 3 Para Calcular Promociones
If Range("P14") = 1 Then
If Range("J14") = "" Then
Call restaurarprecio
Exit Sub
End If
End If
If Range("J14") > Range("I14") Then
Call promocion02
Exit Sub
End If
If Range("J14") = Range("I14") Then
Exit Sub
End If
Call promocion01
End If
End Sub
Y por cada linea debo de configurarlo nuevamente y como son 60 es demasiado y se me hace largo el macro hay manera de simplificarlo

1 respuesta

Respuesta
1
Usa bucle For Next o Do While o Do Until
Por ejm
For r = 12 to 60
   Range("A" & r).Value = "Algo : " & r
Next

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas