Cómo asignar a un Rango la función Worksheet_Change?
Estimados tengo el rango ("V2:AQ2") en los cuales se repite un combo box con 4 opciones (Vacaciones, Dia Libre, Licencia y Borrar). La opción borrar se incluye porque con las tres anteriores se bloquean las celdas.
Al seleccionar una de las opciones se rellenan todas las celdas que cumplan con las condiciones de igualdad establecidas en la macro.
If ActiveSheet.Range("U" & Trim(Str(i%))).Value = Sheets("Usuarios").Range("I4").Value Then
Para ese combo tengo asignada la siguiente Macro...
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$V$2" ThenIf Target.Value = "Licencia" ThenSheets("Imputaciones").SelectActiveSheet.Unprotect "123"i% = 5'Do While ActiveSheet.Cells(i%, 22).Value = Sheets("Usuarios").Range("I4").ValueDo While ActiveSheet.Range("U" & Trim(Str(i%))).Value <> ""If ActiveSheet.Range("U" & Trim(Str(i%))).Value = Sheets("Usuarios").Range("I4").Value ThenActiveSheet.Range("V" & Trim(Str(i%))).Value = "Licencia"ActiveSheet.Range("V" & Trim(Str(i%))).SelectSelection.Locked = TrueSelection.FormulaHidden = FalseEnd Ifi% = i% + 1LoopActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, password:="123"End IfIf Target.Value = "Vacaciones" ThenSheets("Imputaciones").SelectActiveSheet.Unprotect "123"i% = 5'Do While ActiveSheet.Cells(i%, 22).Value = Sheets("Usuarios").Range("I4").ValueDo While ActiveSheet.Range("U" & Trim(Str(i%))).Value <> ""If ActiveSheet.Range("U" & Trim(Str(i%))).Value = Sheets("Usuarios").Range("I4").Value ThenActiveSheet.Range("V" & Trim(Str(i%))).Value = "Vacaciones"ActiveSheet.Range("V" & Trim(Str(i%))).SelectSelection.Locked = TrueSelection.FormulaHidden = FalseEnd Ifi% = i% + 1LoopActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, password:="123"End IfIf Target.Value = "Día Libre" ThenSheets("Imputaciones").SelectActiveSheet.Unprotect "123"i% = 5'Do While ActiveSheet.Cells(i%, 22).Value = Sheets("Usuarios").Range("I4").ValueDo While ActiveSheet.Range("U" & Trim(Str(i%))).Value <> ""If ActiveSheet.Range("U" & Trim(Str(i%))).Value = Sheets("Usuarios").Range("I4").Value ThenActiveSheet.Range("V" & Trim(Str(i%))).Value = "Día Libre"ActiveSheet.Range("V" & Trim(Str(i%))).SelectSelection.Locked = TrueSelection.FormulaHidden = FalseEnd Ifi% = i% + 1LoopActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, password:="123"End IfIf Target.Value = "Borrar" ThenSheets("Imputaciones").SelectActiveSheet.Unprotect "123"i% = 5'Do While ActiveSheet.Cells(i%, 22).Value = Sheets("Usuarios").Range("I4").ValueDo While ActiveSheet.Range("U" & Trim(Str(i%))).Value <> ""If ActiveSheet.Range("U" & Trim(Str(i%))).Value = Sheets("Usuarios").Range("I4").Value ThenActiveSheet.Range("V" & Trim(Str(i%))).Value = ""ActiveSheet.Range("V" & Trim(Str(i%))).SelectSelection.Locked = FalseSelection.FormulaHidden = FalseEnd Ifi% = i% + 1LoopActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, password:="123"End IfEnd If
El problemas es replicarlo para todas las celdas restantes...
If Target.Address = "$W$2"
If Target.Address = "$X$2"
If Target.Address = "$Y$2", etc,etc...
Repeti el mismo código hasta llegar a AQ2 pero me dio error ya que el código es muy largo.
Muchas Gracias.=
