Este fórum está sendo desativado

Depois de 9 anos, este fórum será desativado. Mas calma.... estamos migrando para uma comunidade no DISCORD. Junte-se a nós.

ENTRAR PARA DISCORD

Tópicos relacionados a códigos VBA, gravação de macros, etc.
Por SandroLima
#41724
Boa tarde, pessoal

Estou precisando tirar uma dúvida com um código para inserir a formatação condicional em uma tabela.
Código: Selecionar todos
Option Explicit

Sub Formata_AtvDiarias()
    
    Dim Tabela As ListObject
    
    Set Tabela = wshAtivDiarias.ListObjects("TB_AtividadesDiarias")
    
    Application.ScreenUpdating = False
    Application.EnableEvents = False
    
    'Tabela.DataBodyRange.FormatConditions.Delete
    
    With Tabela.ListColumns("Registro").DataBodyRange.FormatConditions
        .Delete
        .Add Type:=xlExpression, Formula1:= _
        "=E($I15=""Paciente"";OU($M15="""";$M15=""-""))"
        With .Item(.Count)
            .Interior.Color = RGB(255, 235, 156)
            .Font.Color = RGB(156, 101, 0)
        End With
        .Add Type:=xlExpression, Formula1:= _
        "=E($I15=""Paciente"";(EXT.TEXTO($N15;1;LOCALIZAR(""ano"";$N15)-1)*1>=8);OU($L15="""";$L15=""-"";$M15="""";$M15=""-""))"
        With .Item(.Count)
            .Interior.Color = RGB(255, 235, 156)
            .Font.Color = RGB(156, 101, 0)
        End With
        .Add Type:=xlExpression, Formula1:= _
        "=OU($W15=""Aguardando pagamento"";$W15="""";$X15="""")"
        With .Item(.Count)
            .Interior.Color = RGB(255, 235, 156)
            .Font.Color = RGB(156, 101, 0)
        End With
        .Add Type:=xlExpression, Formula1:= _
        "=E($AA15<>"""";$AA15<>""-"";OU($AB15="""";$AB15=""-""))"
        With .Item(.Count)
            .Interior.Color = RGB(255, 235, 156)
            .Font.Color = RGB(156, 101, 0)
        End With
    End With
    
    Set Tabela = Nothing
    
    Application.EnableEvents = True
    Application.ScreenUpdating = True
    
End Sub
Ele terá várias condições para essa mesma coluna além dessas já listadas.

Além disso, serão escritas formatações condicionais diferentes para algumas das outras colunas dessa tabela.

A tabela tem 30 colunas das quais 10 colunas apresentam em média 4 formatações condicional cada uma.

Pergunto:
A estrutura desse código pode ser abreviada ou é dessa maneira mesmo que estou fazendo repetindo os blocos "with" para cada condição?
long long title how many chars? lets see 123 ok more? yes 60

We have created lots of YouTube videos just so you can achieve [...]

Another post test yes yes yes or no, maybe ni? :-/

The best flat phpBB theme around. Period. Fine craftmanship and [...]

Do you need a super MOD? Well here it is. chew on this

All you need is right here. Content tag, SEO, listing, Pizza and spaghetti [...]

Lasagna on me this time ok? I got plenty of cash

this should be fantastic. but what about links,images, bbcodes etc etc? [...]

Estamos migrando para uma comunidade no Discord