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.
  • Avatar do usuário
Por rit
Posts
#30778
boa tarde amigos,

o que tem de errado nesse código, ele esta dando um erro no bloco with
Código: Selecionar todos
ublic Sub ColorirGrafico()

    Dim C As Chart, I As Integer, N As Double
    Dim S1 As Series, S2 As Series
    Dim objCht As ChartObject
    
     
    For Each objCht In Planilha1.ChartObjects
    
    If objCht.Chart.Name <> "0" Then
    
   
    
    'Set C = Planilha1.ChartObjects("1").Chart
    Set S1 = C.SeriesCollection(1)
    Set S2 = C.SeriesCollection(2)
    'Set S1 = S1.Points(I).Format.Fill.ForeColor.RGB = RGB(255, 0, 0)'
    


    For I = 1 To S1.Points.Count
        If S1.Values(I) <= S2.Values(I) And S2.Values(I) > S1.Values(I) Then
            S1.Points(I).Format.Fill.ForeColor.RGB = RGB(0, 0, 255)
            Else
            S1.Points(I).Format.Fill.ForeColor.RGB = RGB(0, 0, 255)
    End If
    
   If S2.Values(I) <= S1.Values(I) Then
            S2.Points(I).Format.Fill.ForeColor.RGB = RGB(0, 255, 0)
            Else
            S2.Points(I).Format.Fill.ForeColor.RGB = RGB(255, 0, 0)
    End If
     
    Next I
    

    
    End If
  
  
Next objCht

   
End Sub


    
  


Private Sub Worksheet_Calculate()
    'se houver formulas
    ColorirGrafico
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
    'verificar quando um valor muda
    ColorirGrafico
End Sub
Avatar do usuário
Por wesleyribeiro123
Posts Avatar
#30812
Amigo
Boa tarde,

A única coisa que percebi que foi a falta de uma estrutura para leitura de teu código. É interessante que você use as tabulações para que o VBA saiba seguir o raciocínio de teu código!

Tente assim:
Código: Selecionar todos
Public Sub ColorirGrafico()
Dim C As Chart, I As Integer, N As Double
Dim S1 As Series, S2 As Series
Dim objCht As ChartObject
   
For Each objCht In Planilha1.ChartObjects
    If objCht.Chart.Name <> "0" Then
        'Set C = Planilha1.ChartObjects("1").Chart
        Set S1 = C.SeriesCollection(1)
        Set S2 = C.SeriesCollection(2)
        'Set S1 = S1.Points(I).Format.Fill.ForeColor.RGB = RGB(255, 0, 0)'
        For I = 1 To S1.Points.Count
            If S1.Values(I) <= S2.Values(I) And S2.Values(I) > S1.Values(I) Then
                S1.Points(I).Format.Fill.ForeColor.RGB = RGB(0, 0, 255)
            Else
                S1.Points(I).Format.Fill.ForeColor.RGB = RGB(0, 0, 255)
            End If
       
            If S2.Values(I) <= S1.Values(I) Then
                S2.Points(I).Format.Fill.ForeColor.RGB = RGB(0, 255, 0)
            Else
                S2.Points(I).Format.Fill.ForeColor.RGB = RGB(255, 0, 0)
            End If
        Next I
    End If
Next objCht
End Sub
Por babdallas
#30814
Anexe a planilha. Só vendo o código não consegui identificar algo que esteja faltando.
Por rit
Posts
#30815
Olá Babdallas tudo bem ?

cara ta em anexo, estou apanhando muito para laços de repetições ja tentei estudar de tudo quanto é forma mas é uma coisa que nao entra na minha cabeça pelo menos nao na pratica a teoria eu entendo mas a pratica esta ruim..

eu só quero que ele faça o mesmo laço que ele faz para as barras do grafico, quero que ele faça para todos os graficos que tiverem no arquivo entende ?

se nao eu preciso ficar fazendo esse código a mesma quantiadde que tiver de grafico.. se tiver 10 graficos no arquivo tenho que escrever isso ai 10 vezes.
Você não está autorizado a ver ou baixar esse anexo.
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