Saltar al contenido

Macro para adaptar FORMATO CONDICIONAL

publicado

Buenas,

Necesito una macro que me haga el siguiente formato condicional, si es posible. Muchas gracias.

1934305662_Sinttulo.thumb.png.c13f6e1dca1a48226d119b1347519fed.png

 

 

imagen.png

Featured Replies

publicado

macro 

Sub colorxcondicion()
Range("B10:K40").Interior.ColorIndex = xlNone
    For i = 10 To 40
        If Cells(i, "I") = "x" Then Range(Cells(i, "B"), Cells(i, "K")).Interior.ColorIndex = 16
        If Cells(i, "B") = "" Or Cells(i, "C") = "" Then Range(Cells(i, "B"), Cells(i, "K")).Interior.ColorIndex = 6
        If Cells(i, "B") <> "" And Cells(i, "C") <> "" Then Range(Cells(i, "B"), Cells(i, "K")).Interior.ColorIndex = xlNone
        If Cells(i, "K") = 1 And Cells(i, "E") <> "" Then Range(Cells(i, "B"), Cells(i, "K")).Interior.ColorIndex = 19
        If Cells(i, "K") > 1 Then Range(Cells(i, "B"), Cells(i, "K")).Interior.ColorIndex = 22
    Next i
    MsgBox "Terminado"
End Sub

 

publicado
  • Autor
Hace 13 horas, temp01 dijo:

macro 


Sub colorxcondicion()
Range("B10:K40").Interior.ColorIndex = xlNone
    For i = 10 To 40
        If Cells(i, "I") = "x" Then Range(Cells(i, "B"), Cells(i, "K")).Interior.ColorIndex = 16
        If Cells(i, "B") = "" Or Cells(i, "C") = "" Then Range(Cells(i, "B"), Cells(i, "K")).Interior.ColorIndex = 6
        If Cells(i, "B") <> "" And Cells(i, "C") <> "" Then Range(Cells(i, "B"), Cells(i, "K")).Interior.ColorIndex = xlNone
        If Cells(i, "K") = 1 And Cells(i, "E") <> "" Then Range(Cells(i, "B"), Cells(i, "K")).Interior.ColorIndex = 19
        If Cells(i, "K") > 1 Then Range(Cells(i, "B"), Cells(i, "K")).Interior.ColorIndex = 22
    Next i
    MsgBox "Terminado"
End Sub

 

Gracias, casi casi me va bien. Pero me hace igual la primera condicion y la última, y por más que la intento adaptar no me lo modifica. Le he puesto a la primera:

If Cells(i, "K") = 1 And Cells(i, "F") <> "" And Cells(i, "I") = "x" Then Range(Cells(i, "B"), Cells(i, "K")).Interior.ColorIndex = 16

Y nada...

publicado
  • Autor

Dejo el archivo. Necesito que en la hoja B PROVISIONALES me ejecute el formato condicional de la hoja INVESTIGACIÓN. Pero con una macro.

MUCHAS GRACIAS!

bbdd_BP_1.3.xlsm

publicado

A ver @laubreeze , viendo tu imagen creo que el problema está en la "x", que en el If la pones en minúscula y en la hoja en mayúscolas... y no es lo mismo ;)

publicado

Hola laubreeze, me parece que tu problema radica en un malentendido del código por las condicionantes. Prueba lo siguiente:

Sub colorxcondicion()
Range("B10:K40").Interior.ColorIndex = xlNone
    For i = 10 To 40
        If Cells(i, "I") = "X" Then Range(Cells(i, "B"), Cells(i, "K")).Interior.ColorIndex = 16
        If Cells(i, "B") = "" Or Cells(i, "C") = "" Then Range(Cells(i, "B"), Cells(i, "K")).Interior.ColorIndex = 6
        If Cells(i, "B") <> "" And Cells(i, "C") <> "" And Cells(i, "I") <> "X" Then Range(Cells(i, "B"), Cells(i, "K")).Interior.ColorIndex = xlNone
        If Cells(i, "K") = 1 And Cells(i, "E") <> "" Then Range(Cells(i, "B"), Cells(i, "K")).Interior.ColorIndex = 19
        If Cells(i, "K") > 1 Then Range(Cells(i, "B"), Cells(i, "K")).Interior.ColorIndex = 22
    Next i
End Sub

 

publicado
  • Autor
Hace 18 horas, Luis paz dijo:

Hola laubreeze, me parece que tu problema radica en un malentendido del código por las condicionantes. Prueba lo siguiente:


Sub colorxcondicion()
Range("B10:K40").Interior.ColorIndex = xlNone
    For i = 10 To 40
        If Cells(i, "I") = "X" Then Range(Cells(i, "B"), Cells(i, "K")).Interior.ColorIndex = 16
        If Cells(i, "B") = "" Or Cells(i, "C") = "" Then Range(Cells(i, "B"), Cells(i, "K")).Interior.ColorIndex = 6
        If Cells(i, "B") <> "" And Cells(i, "C") <> "" And Cells(i, "I") <> "X" Then Range(Cells(i, "B"), Cells(i, "K")).Interior.ColorIndex = xlNone
        If Cells(i, "K") = 1 And Cells(i, "E") <> "" Then Range(Cells(i, "B"), Cells(i, "K")).Interior.ColorIndex = 19
        If Cells(i, "K") > 1 Then Range(Cells(i, "B"), Cells(i, "K")).Interior.ColorIndex = 22
    Next i
End Sub

 

No sé por qué razón, pero me sigue poniendo del mismo color las que llevan X que las que no (primera y última condición en el mismo color)... Las X deberían ir en gris, y tampoco es cuestión de mayúsculas o minúsculas como me comentábais. Lo dejo aquí tal cual está por si queréis verlo.

Aprovecho para preguntaros otra cosa, tampoco estos son los mismos colores que tengo en la hoja "investigación" ¿Cómo tendría que hacer para conseguir aquellos tonos? porque he probado con RGB(166,166,166) por ejemplo, al final del código del color, y da error.

No sé si saldré de esta XD.

bbdd_BP_1.5.xlsm

Archivado

Este tema está ahora archivado y está cerrado a más respuestas.