Public Sub Calcular()
A_Declarar_Constantes.Declarar
Excel.Application.Calculation = xlCalculationManual
Max_Row = (Sheets("01_Analisis").UsedRange.Row) + Sheets("01_Analisis").UsedRange.Rows.Count - 1
Dim Max_Row_A01 As Long
Max_Row_A01 = Max_Row
Dim Max_Row_A02 As Long
Dim Temp_Max_Row_Analisis_01 As Long
Dim N As Double: N = 2
'Borro todo
Max_Row_A02 = (Sheets("02_Analisis").UsedRange.Row) + Sheets("02_Analisis").UsedRange.Rows.Count - 1
'On Error Resume Next
On Error GoTo Salta:
Sheets("02_Analisis").Range(Cells(2, 1), Cells(Max_Row_A02, 18)).Clear
Salta:
If Err.Number = 1004 Then
H.Activate
Sheets("02_Analisis").Range(Cells(2, 1), Cells(Max_Row_A02, 18)).Clear
H.Visible = xlSheetVeryHidden
End If
'Coloco todos los hitos del esquema
For Bcle = 2 To Max_Row
With Excel.Sheets("02_Analisis")
If Not Sheets("01_Analisis").Cells(Bcle, 2) = .Cells(N - 1, 1) Then
.Cells(N, 1) = Sheets("01_Analisis").Cells(Bcle, 2)
.Cells(N, 1).NumberFormat = "dd-mmm'yy"
N = N + 1
End If
End With
Next
Max_Row_A02 = N - 1
For Bcle = 2 To Max_Row_A02
With Excel.Sheets("02_Analisis")
If CDate(Excel.Sheets("02_Analisis").Cells(Bcle, 1)) <= Date_Analisis Then
.Cells(Bcle, 2).FormulaR1C1 = "=IFERROR(SUMIFS('01_Analisis'!C[4],'01_Analisis'!C[-1],R1C2,'01_Analisis'!C,'02_Analisis'!RC[-1])+R[-1]C,SUMIFS('01_Analisis'!C[4],'01_Analisis'!C[-1],R1C2,'01_Analisis'!C,'02_Analisis'!RC[-1]))"
.Cells(Bcle, 4).FormulaR1C1 = "=IFERROR(SUMIFS('01_Analisis'!C[2],'01_Analisis'!C[-3],R1C4,'01_Analisis'!C[-2],'02_Analisis'!RC[-3])+R[-1]C,SUMIFS('01_Analisis'!C[2],'01_Analisis'!C[-3],R1C4,'01_Analisis'!C[-2],'02_Analisis'!RC[-3]))"
.Cells(Bcle, 5).FormulaR1C1 = "=IFERROR(SUMIFS('01_Analisis'!C[1],'01_Analisis'!C[-4],R1C5,'01_Analisis'!C[-3],'02_Analisis'!RC[-4])+R[-1]C,SUMIFS('01_Analisis'!C[1],'01_Analisis'!C[-4],R1C5,'01_Analisis'!C[-3],'02_Analisis'!RC[-4]))"
.Cells(Bcle, 6).FormulaR1C1 = "=RC[-1]-RC[-4]"
.Cells(Bcle, 7).FormulaR1C1 = "=+RC[-2]-RC[-3]"
.Cells(Bcle, 8).FormulaR1C1 = "=RC[-3]/RC[-6]"
.Cells(Bcle, 9).FormulaR1C1 = "=+RC[-4]/RC[-5]"
.Cells(Bcle, 10).FormulaR1C1 = "=MAX(C[-8]:C[-7])+RC[-6]-RC[-5]"
.Cells(Bcle, 11).FormulaR1C1 = "=MAX(C[-9]:C[-8])/RC[-2]"
.Cells(Bcle, 12).FormulaR1C1 = "=RC[-8]+((MAX(C[-10]:C[-9])-RC[-7])/(RC[-3]*RC[-4]))"
.Cells(Bcle, 13).FormulaR1C1 = "=(RC[-3]-RC[-8])/(MAX(C[-11]:C[-10])-RC[-9])"
.Cells(Bcle, 14).FormulaR1C1 = "=(RC[-3]-RC[-10])/(MAX(C[-12]:C[-11])-RC[-9])"
.Cells(Bcle, 15).FormulaR1C1 = "=(RC[-3]-RC[-11])/(MAX(C[-13]:C[-12])-RC[-10])"
End If
If CDate(Excel.Sheets("02_Analisis").Cells(Bcle, 1)) = Date_Analisis Then
'.Cells(Bcle, 2).FormulaR1C1 = "=IFERROR(SUMIFS('01_Analisis'!C[4],'01_Analisis'!C[-1],R2C2,'01_Analisis'!C,'02_Analisis'!RC[-1])+R[-1]C,SUMIFS('01_Analisis'!C[4],'01_Analisis'!C[-1],R2C2,'01_Analisis'!C,'02_Analisis'!RC[-1]))"
.Cells(Bcle, 3).FormulaR1C1 = "=RC[-1]"
'If Cells(Bcle, 4) = "" Then Cells(Bcle, 4).FormulaR1C1 = "=+R[-1]C"
'If Cells(Bcle, 5) = "" Then Cells(Bcle, 5).FormulaR1C1 = "=+R[-1]C"
'.Cells(Bcle, 6).FormulaR1C1 = "=RC[-1]-RC[-4]"
'.Cells(Bcle, 7).FormulaR1C1 = "=+RC[-2]-RC[-3]"
'.Cells(Bcle, 8).FormulaR1C1 = "=RC[-3]/RC[-6]"
'.Cells(Bcle, 9).FormulaR1C1 = "=+RC[-4]/RC[-5]"
.Cells(Bcle, 16).FormulaR1C1 = "=RC[-13]"
.Cells(Bcle, 17).FormulaR1C1 = "=+RC[-13]"
.Cells(Bcle, 18).FormulaR1C1 = "=+RC[-13]"
End If
If CDate(Excel.Sheets("02_Analisis").Cells(Bcle, 1)) > Date_Analisis Then
.Cells(Bcle, 3).FormulaR1C1 = "=IFERROR(SUMIFS('01_Analisis'!C[3],'01_Analisis'!C[-2],R1C3,'01_Analisis'!C[-1],'02_Analisis'!RC[-2])+R[-1]C,SUMIFS('01_Analisis'!C[3],'01_Analisis'!C[-2],R1C3,'01_Analisis'!C[-1],'02_Analisis'!RC[-2]))"
End If
End With
Next
Excel.Application.Calculation = xlCalculationAutomatic
End Sub
No hay comentarios:
Publicar un comentario