Tenho esta rotina:
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Sub allinoneDos()
Cells(ActiveCell.Row, 1).Select
base = ActiveCell.Address
Range("A1").Select
Cells.Find(What:="Inventory Projected", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
ActiveCell.Offset(1, 3).Select
inventario = ActiveCell.Address
net = "$d$3"
Range(base).Select
ActiveCell.Offset(0, 3).Select
linha = 0
'=WeeksofSale($D$3:$CC$3;D32)*7
While Cells(ActiveCell.Row, 1).Value <> ""
inicio = ActiveCell.Address
For i = 0 To 77
ActiveCell.formula = "=WeeksofSale(" & Range(net).Offset(linha, i + 1).Address & ":" & Range(net).Offset(linha, 77).Address & _
"," & Range(inventario).Offset(linha, i).Address & ")*7"
ActiveCell.Offset(0, 1).Select
Next i
linha = linha + 1
Range(inicio).Select
ActiveCell.Offset(1, 0).Select
Wend
End Sub
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Private Function WeeksOfSale(Demand As Range, QOH As Double)
Dim endOfFC, qohnegflag As Boolean
Dim cont As Integer
i = 1
WeeksOfSale = 0
totdemand = 0
endOfFC = False
qohnegflag = False
If QOH < 0 Then 'Set negative QOH to positive to calc. negative DOS
qohnegflag = True
QOH = QOH * -1
End If
For i = 1 To Demand.Cells.Count
If Not (QOH - (totdemand + Demand.Cells(1, i).Value)) < 0 Then
totdemand = totdemand + Demand.Cells(1, i).Value
If i = Demand.Cells.Count Then
endOfFC = True
End If
Else
lastFcValue = Demand.Cells(1, i).Value
WeeksOfSale = (i - 1) * 1
i = Demand.Cells.Count
End If
Next i
If endOfFC = True Then
WeeksOfSale = 999
End If
If QOH > 0 And endOfFC = False Then
WeeksOfSale = WeeksOfSale + ((QOH - totdemand) / lastFcValue) * 1
End If
cont = cont + 1
If qohnegflag = True Then
WeeksOfSale = WeeksOfSale * -1
End If
If cont > 1 Then
Exit Function
End If
WeeksOfSale = Round(WeeksOfSale, 1)
End Function
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Quando ele roda a rotina entra nesta function e fica em um looping nela...
Para evitar, estou desabilitando o cálculo automático, mas é uma opção ruim para o resto da rotina...
Obrigada desde já
Postado : 21/05/2015 9:30 am