erro em tempo de ex...
 
Notifications
Clear all

erro em tempo de execução - tipos incompatíveis

2 Posts
2 Usuários
0 Likes
476 Visualizações
(@cimerio)
Posts: 47
Trusted Member
Topic starter
 

pessoal, estou com problemas no código abaixo:

basicamente, a quinta coluna da planilha gru traz valores em moeda que podem ou não estar preenchidos entre as linhas 43 a 56.

porém, eu preciso dividir esses valores em 80% e 20% para jogar em outro lugar.

não consigo, porque sempre  aparece tipos incompatíveis na linha que tento aplicar o calculo (taxa(y) = Worksheets("gru").Cells(x, 5).Value * 0.2)

Sub dividirValores_Taxa()
Dim principal(13) As Currency
Dim taxa(13) As Currency
For x = 43 To 56
    If Worksheets("gru").Cells(x, 5) > 0 Then
        y = 0
        taxa(y) = Worksheets("gru").Cells(x, 5).Value * 0.2
        ' taxa(y) = Worksheets("gru").Cells(x, 5).Value / 10 * 2
        principal(y) = Worksheets("gru").Cells(x, 5).Value - pss(y)
        Debug.Print taxa(y)
        Debug.Print principal(y)
        y = y + 1
    End If
Next x
End Sub
 
Postado : 19/06/2023 3:18 pm
nelsonst
(@nelsonst)
Posts: 38
Eminent Member
 

O erro de tipos incompatíveis é provavelmente devido à declaração das matrizes "principal" e "taxa" como "Currency". Além disso, a variável "y" não é reinicializada para cada nova linha da planilha. fiz uns ajustes... veja se corrigiu !

 

 

Sub dividirValores_Taxa()


Dim principal(13) As Double
Dim taxa(13) As Double
Dim y As Integer

y = 0

For x = 43 To 56
If Worksheets("gru").Cells(x, 5).Value > 0 Then
taxa(y) = Worksheets("gru").Cells(x, 5).Value * 0.2
principal(y) = Worksheets("gru").Cells(x, 5).Value * 0.8
Debug.Print taxa(y)
Debug.Print principal(y)
y = y + 1
End If
Next x
End Sub
 
Postado : 01/08/2023 4:32 pm