Boa tarde,
Caros,
Sou iniciante em vba e estou com um problema.
ao criar um script, apareceu o erro de código muito grande, entao resolvi diminuir algumas etapas criando subs secundárias e chamando-as via "call".
porém ao cria-las tive um problema de tipo incompativel de argumento ByRef. Li vários artigos e problemas em varios sites e nao consegui resolver.
poderiam me ajudar?
Vou colar abaixo partes do meu código e desde já agradeço a ajuda!
'Declaracao de variaveis Publicas
Public contagemultimalinha As Long, idlinha As Long, loopcalculado As Long, menordata As Long, dataobs As Long, linhaobs As Long, linhastotaissuporte As Long, procuraid As Long, linhassuporte As Long
Public horaobs As Double, somadatahora As Double, somadatahoraobs As Double, menorhora As Double, min5 As Double, QUARTO_HORA As Double, datahoraobs As Double, menordatahora As Double
Public cenarioobs As Integer, operativos As Integer, limitefinger As Integer, fingeroperativoobs As Integer, valordalinhafinalarvl As Integer, valordalinhafinaldept As Integer, valordalinhanreboca As Integer, qtdacftsnreboca As Integer, fingersrestantes As Integer, linhapousodec As Integer
Public terminalobs As String, alocacaoobs As String, fingerouremota As String
' atribuicao de valores das variaveis
For linhaobs = 2 To contagemultimalinha
Application.ScreenUpdating = True
Sheets("Planilha Contagem ACFT").Select
dataobs = Range("A" & linhaobs).Value
horaobs = Range("B" & linhaobs).Value
datahoraobs = dataobs + horaobs
terminalobs = Range("C" & linhaobs).Value
alocacaoobs = Range("D" & linhaobs).Value
cenarioobs = Range("E" & linhaobs).Value
operativos = Range("J" & linhaobs).Value
limitefinger = Range("G" & linhaobs).Value
menordatahora = menordata + menorhora
................
' chamando a sub publica:
Select Case cenarioobs
' CENARIO 1
Case 1
'Call filtroscen1(dataobs, horaobs, terminalobs, alocacaoobs, lultimalinha)
'filtroscen1 sub publica
Public Sub filtrosce1(ByRef lultimalinha As Long, ByRef terminalobs As String, ByRef dataobs As Long, ByRef horaobs As Double)
' filtrando Arvl com reboque
Dim lultimalinha1 As Long
Dim terminalobs1 As String
Dim alocacaoobs1 As String
Dim dataobs1 As Long
Dim horaobs1 As Double
lultimalinha1 = lultimalinha.Value
terminalobs1 = terminalobs.Value
dataobs1 = dataobs.Value
horaobs1 = horaobs.Value
Sheets("Banco_de_Dados").Select
Set worksheet1 = ActiveSheet
If worksheet1.AutoFilterMode Then
worksheet1.AutoFilter.ShowAllData
Else
Selection.AutoFilter
End If
somadatahora = dataobs + horaobs
ActiveSheet.Range("$A$1:$A" & lultimalinha).AutoFilter Field:=34, Criteria1:= _
"<=" & somadatahora, Operator:=xlAnd
ActiveSheet.Range("$A$1:$A" & lultimalinha).AutoFilter Field:=42, Criteria1:= _
">=" & somadatahora, Operator:=xlAnd
ActiveSheet.Range("$A$1:$A" & lultimalinha).AutoFilter Field:=28, Criteria1:= _
"=" & terminalobs1, Operator:=xlAnd
ActiveSheet.Range("$A$1:$A" & lultimalinha).AutoFilter Field:=30, Criteria1:="S"
Range("A50000").Select
Selection.End(xlUp).Select
End Sub
qualquer coisa passo a planilha para darem uma olhada!
att
Riczmud
Postado : 29/03/2018 1:49 pm