Boa noite, sou novato no forum, e nunca mexi com VBA, programo em VB... quase igual, mas so quase... estou com uma planilha para tentar resolver um problema... vejam o codigo:
------------------------------------------------------------------------------------------------------------------------
Sub Relatorio_Analitico()
With Application
.Calculation = xlManual
.MaxChange = 0.001
End With
Data_Inicial = Sheets("Movimento Diário").Cells(8, 9).Select
Data_Final = Sheets("Movimento Diário").Cells(8, 6).Select
Produto = Sheets("Movimento Diário").Cells(8, 4).Select
Sheets("Movimento Diário").Range(Cells(12, 3), Cells(65536, 9)).ClearContents
l = 10
Lr = 11
Do
l = l + 1
Data = Sheets("Lançamentos").Cells(l, 2)
If Data = 0 Then Exit Do
Apelido = Sheets("Lançamentos").Cells(l, 3)
If Data >= Data_Inicial And Data <= Data_Final And Apelido = Produto Then
Apelido = Sheets("Lançamentos").Cells(l, 3)
Descricao = Sheets("Lançamentos").Cells(l, 4)
Unid = Sheets("Lançamentos").Cells(l, 5)
Quantidade = Sheets("Lançamentos").Cells(l, 6)
Movimento = Sheets("Lançamentos").Cells(l, 7)
ValorUnit = Sheets("Lançamentos").Cells(l,
Sheets("Movimento Diário").Activate
Qtd = Application.CountIf(Sheets("Movimento Diário").Range(Cells(1, 3), Cells(65536, 3)), Format(Data, "dd/mm/yy"))
If Qtd = 1 Then
Lr = Application.Match(Format(Data, "dd/mm/yy"), Sheets("Movimento Diário").Range(Cells(1, 3), Cells(65536, 3)), 0)
Else
Lr = 11
End If
Do
Lr = Lr + 1
DataLInha = Sheets("Movimento Diário").Cells(Lr, 3)
If DataLInha = 0 Then Exit Do
Loop
Select Case Movimento
Case Is = "E"
Sheets("Movimento Diário").Cells(Lr, 3) = "'" & Format(Data, "dd/mm/yy")
Sheets("Movimento Diário").Cells(Lr, 4) = Quantidade
Sheets("Movimento Diário").Cells(Lr, 5) = ValorUnit
Sheets("Movimento Diário").Cells(Lr, 6) = Quantidade * ValorUnit
Case Is = "S"
Sheets("Movimento Diário").Cells(Lr, 3) = "'" & Format(Data, "dd/mm/yy")
Sheets("Movimento Diário").Cells(Lr, 7) = Quantidade
Sheets("Movimento Diário").Cells(Lr,
= "=If(RC[-1]=0,0,RC11)" 'ValorUnit
Sheets("Movimento Diário").Cells(Lr, 9) = Quantidade * ValorUnit
End Select
If Lr = 12 Then
Sheets("Movimento Diário").Cells(Lr, 10) = "=RC[-6]-RC[-3]"
Else
Sheets("Movimento Diário").Cells(Lr, 10) = "=RC[-6]-RC[-3]+R[-1]C"
End If
Sheets("Movimento Diário").Cells(Lr, 11) = "=if(RC[-7]<>0,RC[1]/RC[-1],R[-1]C)"
If Lr = 12 Then
Sheets("Movimento Diário").Cells(Lr, 12) = "=RC[-6]-RC[-3]"
Else
Sheets("Movimento Diário").Cells(Lr, 12) = "=RC[-6]-RC[-3]+R[-1]C"
End If
If Lr = 12 Then
Sheets("Movimento Diário").Cells(Lr, 13) = 0
Else
Sheets("Movimento Diário").Cells(Lr, 13) = "=if(and(R[-1]C[-2]<>0,RC[-10]<>0),(RC[-2]-R[-1]C[-2])/R[-1]C[-2],0)"
End If
End If
Loop
With Application
.Calculation = xlAutomatic
.MaxChange = 0.001
End With
MsgBox ("Fim de consulta!!")
End Sub
---------------------------------------------------------------------------------------------------------------
Quando mando executar, me apresenta o erro:
Erro em tempo de execução "9"
subscrito fora do intervalo
Dai ele marca a linha (Data_Inicial = Sheets("Movimento Diário").Cells(8, 9).Select), comentei essa linha, ele marca a proxima...
percebi q se eu digitar o PONTO, antes d Cells, nao me mostra a funcao CELLS, nao sei se no VBA é igual ao vc, q no sinal do PONTO, sempre vem funcoes...
me parece q tem algo desativado, tipo REFERENCES...
alguem pode dar alguma dica? ou se preferir falar no MSN ( carlynhos77@hotmail.com )