Ejecutar Macro en todo el libro. Pregunta para Elsa Matilde.

Hola Elsa, como hemos hablado, necesitaría que me ayudaras para poder ejecutar la macro en todo el libro y que dandole al boton se pintara todo el libro segun las condiciones:

Private Sub Worksheet_Change(ByVal Target As Range)

'Cambia el color de la celda COL F - - CONTROLA COL G, PINTA COL I:HA 'Ajustada por Elsamatilde


If Not Intersect(Target, Columns("G")) Is Nothing Then

'Application.EnableEvents = False

Select Case UCase(Cells(Target.Row, "G"))

Case "FORECAST" Cells(Target.Row, "G").Interior.ColorIndex = 20

Range(Cells(Target.Row, "I"), Cells(Target.Row, "HA")).Interior.ColorIndex = 20

Case "ACTUAL" Cells(Target.Row, "G").Interior.ColorIndex = 44

Range(Cells(Target.Row, "I"), Cells(Target.Row, "HA")).Interior.ColorIndex = 44

Case "NEW FORECAST", "NEWFORECAST" Cells(Target.Row, "G").Interior.ColorIndex = 43 Range(Cells(Target.Row, "I"), Cells(Target.Row, "HA")).Interior.ColorIndex = 43

End Select 'Application.EnableEvents = True

End If

End Sub

Muchas gracias por tu ayuda !!!

1 respuesta

Respuesta
1

Ya la tomo... en el transcurso del día te la responderé. No finalices aún.

La nueva macro la tenés que colocar en un módulo (desde el Editor, insertar módulo y allí la copias)

Lo que hace es evaluar desde qué hoja se la está llamando para ajustar el rango de acción, ya que se trata de col diferentes.

Sub ASIGNA_COLOR()
'x Elsamatilde
'Cambia el color de celdas según de qué hoja se trate.
'Atajo de teclado: Ctrl a (mayúsc o minúsc)
If ActiveSheet.Name = "Comparativa Materiales" Then
 colx = 6: colini = 8: colfin = 19 'CONTROLA COL F, PINTA COL H:S
ElseIf ActiveSheet.Name = "Comparativa Horas" Then
 colx = 7: colini = 9: colfin = 20 'CONTROLA COL G, PINTA COL I:T
'agregar otras hojas si hiciera falta
End If
'inicia en fila 16
Cells(16, colx).Select
'recorre la col hasta encontrar celda vacía
While ActiveCell.Value <> ""
 Select Case UCase(ActiveCell.Value)
 Case "FORECAST"
 ActiveCell.Interior.ColorIndex = 24
 Range(Cells(ActiveCell.Row, colini), Cells(ActiveCell.Row, colfin)).Interior.ColorIndex = 24
 Case "ACTUAL"
 ActiveCell.Interior.ColorIndex = 44
 Range(Cells(ActiveCell.Row, colini), Cells(ActiveCell.Row, colfin)).Interior.ColorIndex = 44
 Case "NEW FORECAST", "NEWFORECAST"
 ActiveCell.Interior.ColorIndex = 43
 Range(Cells(ActiveCell.Row, colini), Cells(ActiveCell.Row, colfin)).Interior.ColorIndex = 43
 End Select
'pasa a la fila sgte y repite el bucle
ActiveCell.Offset(1, 0).Select
Wend
End Sub

Podes colocar un botón en cada hoja o asignarle un atajo de teclado tal como verás en el libro que te estoy enviando.

Nota: estos temas los tengo explicados en la sección Macros de mi sitio.

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas