0% found this document useful (0 votes)
40 views

Código VBA

This document contains VBA code for macros associated with different worksheets and a workbook in an Excel file. The code includes macros that run on worksheet changes to update dependent cells, macros that format cells when certain values are changed, and macros that control the visibility of worksheets and forms on workbook open. The document also includes code for callbacks related to a custom ribbon UI.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

Código VBA

This document contains VBA code for macros associated with different worksheets and a workbook in an Excel file. The code includes macros that run on worksheet changes to update dependent cells, macros that format cells when certain values are changed, and macros that control the visibility of worksheets and forms on workbook open. The document also includes code for callbacks related to a custom ribbon UI.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 59

Hoja 1 (Cabeza)

Private Sub Worksheet_Change(ByVal Target As Excel.Range)


If Target.Address(False, False) = "D5" Then
Celda = ActiveCell.Address
Range("D6").Select
ActiveCell.FormulaR1C1 = "=+Visc_Cinematica(R[-1]C)"
Range(Celda).Select
'Iteraciones_Hojas.Calcular_I
End If
If Target.Address(False, False) = "D10" Then
Celda = ActiveCell.Address

78
Range("D11").Select
ActiveCell.FormulaR1C1 = "=+(25.4/1000)*R[-1]C"
Range(Celda).Select
'Iteraciones_Hojas.Calcular_I
End If
'If Not Intersect(Target, Range("D8:D9")) Is Nothing Then Iteraciones_Hojas.Calcular_I
'If Not Intersect(Target, Range("D13:D15")) Is Nothing Then Iteraciones_Hojas.Calcular_I
End Sub
Hoja 2 (Diámetro)

Private Sub Worksheet_Change(ByVal Target As Excel.Range)


If Target.Address(False, False) = "D5" Then Iteraciones_Hojas.Calcular_II
If Not Intersect(Target, Range("D8:D14")) Is Nothing Then Iteraciones_Hojas.Calcular_II
End Sub

79
Hoja 3(UnaTuberia)

Private Sub Worksheet_Change(ByVal Target As Excel.Range)


If Target.Address(False, False) = "D5" Then
Celda = ActiveCell.Address
Range("D6").Select
ActiveCell.FormulaR1C1 = "=+Visc_Cinematica(R[-1]C)"
Range(Celda).Select
Iteraciones_Hojas.Calcular_III
End If
If Target.Address(False, False) = "D10" Then
Celda = ActiveCell.Address

80
Range("D11").Select
ActiveCell.FormulaR1C1 = "=+(25.4/1000)*R[-1]C"
Range(Celda).Select
Iteraciones_Hojas.Calcular_III
End If
If Not Intersect(Target, Range("D8:D9")) Is Nothing Then Iteraciones_Hojas.Calcular_III
If Not Intersect(Target, Range("D13:D15")) Is Nothing Then Iteraciones_Hojas.Calcular_III
End Sub
Hoja 4(TuberiaSerie)

Private Sub Worksheet_Change(ByVal Target As Excel.Range)


If Target.Address(False, False) = "C5" Then
Celda = ActiveCell.Address
Range("C6").Select
ActiveCell.FormulaR1C1 = "=+Visc_Cinematica(R[-1]C)"
Range(Celda).Select
Iteraciones_Hojas.Calcular_IV
End If
If Not Intersect(Target, Range("C8:C9")) Is Nothing Then Iteraciones_Hojas.Calcular_IV
If Not Intersect(Target, Range("C12:F100")) Is Nothing Then Iteraciones_Hojas.Calcular_IV

81
If Not Intersect(Target, Range("H12:H100")) Is Nothing Then Iteraciones_Hojas.Calcular_IV
End Sub
Hoja 5(TuberiaParalelo)

Private Sub Worksheet_Change(ByVal Target As Excel.Range)


If Target.Address(False, False) = "C5" Then
Celda = ActiveCell.Address
Range("C6").Select
ActiveCell.FormulaR1C1 = "=+Visc_Cinematica(R[-1]C)"
Range(Celda).Select
Iteraciones_Hojas.Calcular_V
End If
If Not Intersect(Target, Range("C8:C30")) Is Nothing Then Iteraciones_Hojas.Calcular_V
If Not Intersect(Target, Range("M6:M8")) Is Nothing Then Iteraciones_Hojas.Calcular_V

82
End Sub
Hoja 6(Desarenador)

Private Sub Worksheet_Change(ByVal Target As Excel.Range)


If Target.Address(False, False) = "E8" Then
Celda = ActiveCell.Address
Range("E11").Select
ActiveCell.FormulaR1C1 = "=+B/H"
Range("E12").Select
ActiveCell.FormulaR1C1 = "=+L/B"
Range("E41").Select
ActiveCell.FormulaR1C1 = _
"=+VLOOKUP(R[-23]C,R10C11:R12C19," & _

83
"IF(R[-22]C=R[-32]C[7],2," & _
"IF(R[-22]C=R[-32]C[8],3," & _
"IF(R[-22]C=R[-32]C[9],4," & _
"IF(R[-22]C=R[-32]C[10],5," & _
"IF(R[-22]C=R[-32]C[11],6," & _
"IF(R[-22]C=R[-32]C[12],7," & _
"IF(R[-22]C=R[-32]C[13],8," & _
"IF(R[-22]C=R[-32]C[14],9)))))))),FALSE)"
Range(Celda).Select
End If

If Not Intersect(Target, Range("E9:E10")) Is Nothing Then


Celda = ActiveCell.Address
Range("E41").Select
ActiveCell.FormulaR1C1 = _
"=+VLOOKUP(R[-23]C,R10C11:R12C19," & _
"IF(R[-22]C=R[-32]C[7],2," & _
"IF(R[-22]C=R[-32]C[8],3," & _
"IF(R[-22]C=R[-32]C[9],4," & _
"IF(R[-22]C=R[-32]C[10],5," & _
"IF(R[-22]C=R[-32]C[11],6," & _
"IF(R[-22]C=R[-32]C[12],7," & _
"IF(R[-22]C=R[-32]C[13],8," & _
"IF(R[-22]C=R[-32]C[14],9)))))))),FALSE)"
Range(Celda).Select
End If

84
If Not Intersect(Target, Range("E15:E19")) Is Nothing Then
Celda = ActiveCell.Address
Range("E41").Select
ActiveCell.FormulaR1C1 = _
"=+VLOOKUP(R[-23]C,R10C11:R12C19," & _
"IF(R[-22]C=R[-32]C[7],2," & _
"IF(R[-22]C=R[-32]C[8],3," & _
"IF(R[-22]C=R[-32]C[9],4," & _
"IF(R[-22]C=R[-32]C[10],5," & _
"IF(R[-22]C=R[-32]C[11],6," & _
"IF(R[-22]C=R[-32]C[12],7," & _
"IF(R[-22]C=R[-32]C[13],8," & _
"IF(R[-22]C=R[-32]C[14],9)))))))),FALSE)"
Range(Celda).Select
End If
If Target.Address(False, False) = "E20" Then
Celda = ActiveCell.Address
Range("E21").Select
ActiveCell.FormulaR1C1 = "=10000*Visc_Cinematica(R[-1]C)"
Range("E41").Select
ActiveCell.FormulaR1C1 = _
"=+VLOOKUP(R[-23]C,R10C11:R12C19," & _
"IF(R[-22]C=R[-32]C[7],2," & _
"IF(R[-22]C=R[-32]C[8],3," & _
"IF(R[-22]C=R[-32]C[9],4," & _
"IF(R[-22]C=R[-32]C[10],5," & _
"IF(R[-22]C=R[-32]C[11],6," & _

85
"IF(R[-22]C=R[-32]C[12],7," & _
"IF(R[-22]C=R[-32]C[13],8," & _
"IF(R[-22]C=R[-32]C[14],9)))))))),FALSE)"
Range(Celda).Select
End If
If Target.Address(False, False) = "E23" Then
Celda = ActiveCell.Address
Range("E35").Select
ActiveCell.FormulaR1C1 = "=IF(R[-12]C=""SI"",0.02,0.01)"
Range("E41").Select
ActiveCell.FormulaR1C1 = _
"=+VLOOKUP(R[-23]C,R10C11:R12C19," & _
"IF(R[-22]C=R[-32]C[7],2," & _
"IF(R[-22]C=R[-32]C[8],3," & _
"IF(R[-22]C=R[-32]C[9],4," & _
"IF(R[-22]C=R[-32]C[10],5," & _
"IF(R[-22]C=R[-32]C[11],6," & _
"IF(R[-22]C=R[-32]C[12],7," & _
"IF(R[-22]C=R[-32]C[13],8," & _
"IF(R[-22]C=R[-32]C[14],9)))))))),FALSE)"
Range(Celda).Select
End If
If Not Intersect(Target, Range("H27:H28")) Is Nothing Then
Celda = ActiveCell.Address
Range("E41").Select
ActiveCell.FormulaR1C1 = _
"=+VLOOKUP(R[-23]C,R10C11:R12C19," & _

86
"IF(R[-22]C=R[-32]C[7],2," & _
"IF(R[-22]C=R[-32]C[8],3," & _
"IF(R[-22]C=R[-32]C[9],4," & _
"IF(R[-22]C=R[-32]C[10],5," & _
"IF(R[-22]C=R[-32]C[11],6," & _
"IF(R[-22]C=R[-32]C[12],7," & _
"IF(R[-22]C=R[-32]C[13],8," & _
"IF(R[-22]C=R[-32]C[14],9)))))))),FALSE)"
Range(Celda).Select
End If
End Sub
Hoja 7(Alcantarillados)

Private Sub Worksheet_Change(ByVal Target As Excel.Range)


If Not Intersect(Target, Range("E6:E7")) Is Nothing Then
Celda = ActiveCell.Address
Range("F7").Select
ActiveCell.FormulaR1C1 = "=+R[-1]C[-1]-RC[-1]"
Range("E23").Select
ActiveCell.FormulaR1C1 = "=+ABS(R[-16]C[1])/R[-10]C"
Range(Celda).Select
End If
If Not Intersect(Target, Range("E11:F12")) Is Nothing Then

87
Celda = ActiveCell.Address
Range("E13").Select
ActiveCell.FormulaR1C1 = "=+SQRT((R[-2]C-R[-1]C) ^2+(R[-2]C[1]-R[-1]C[1])^2)"
Range("E23").Select
ActiveCell.FormulaR1C1 = "=+ABS(R[-16]C[1])/R[-10]C"
Range(Celda).Select
End If
If Target.Address(False, False) = "E15" Then
Celda = ActiveCell.Address
Range("E16").Select
ActiveCell.FormulaR1C1 = "=+Visc_Cinematica(R[-1]C)"
Range("E23").Select
ActiveCell.FormulaR1C1 = "=+ABS(R[-16]C[1])/R[-10]C"
Range(Celda).Select
End If
If Target.Address(False, False) = "F7" Then
Celda = ActiveCell.Address
Range("E23").Select
ActiveCell.FormulaR1C1 = "=+ABS(R[-16]C[1])/R[-10]C"
Range(Celda).Select
End If
If Target.Address(False, False) = "E13" Then
Celda = ActiveCell.Address
Range("E23").Select
ActiveCell.FormulaR1C1 = "=+ABS(R[-16]C[1])/R[-10]C"
Range(Celda).Select
End If

88
End Sub
ThisWorkbook

Private Sub Workbook_Open()


With Application
.Iteration = True
.MaxIterations = 1000
.MaxChange = 0.000000001
.Calculation = xlAutomatic
'Simbolos decimales
.DecimalSeparator = "."
.ThousandsSeparator = ","
.UseSystemSeparators = False

89
End With
Dim Current As Worksheet
For Each Current In Worksheets
If Current.Name = "Hoja1" Then Exit For
'MsgBox Current.Name
Current.visible = False
Next
'For Each img In ActiveSheet.Shapes
' ActiveSheet.Shapes.Range(Array(1)).Select
' Selection.Delete
'Next img
Range("A1").Select
Presentacion.Show
End Sub

90
Formularios (Presentación)

91
Private Sub UserForm_Activate()
Application.OnTime Now + TimeValue("00:00:07"), "KillTheForm"
End Sub
Módulos (basCallbacks)

' Globals

Public gobjRibbon As IRibbonUI

Public bolEnabled As Boolean ' Used in Callback "getEnabled"


' Further informations in Callback "getEnabled"
' Für Callback "getEnabled"
' Genauere Informationen in Callback "getEnabled".

Public bolVisible As Boolean ' Used in Callback "getVisible"

92
' More information in Callback "getVisible
' Für Callback "getVisible"
' Further informations in Callback "getVisible

' For Sample Callback "GetContent"


' Fuer Beispiel Callback "GetContent"
Public Type ItemsVal
id As String
label As String
imageMso As String
End Type
' Callbacks

Public Sub OnRibbonLoad(ribbon As IRibbonUI)


'Callbackname in XML File "onLoad"

Set gobjRibbon = ribbon


End Sub

Public Sub OnActionButton(control As IRibbonControl)


'Callback in XML File "onAction"

' Callback for event button click


' Callback für Button Click

93
Select Case control.id
Case "btn1"
Sheets("Cabeza").visible = True
Sheets("Cabeza").Select
Case "btn2"
Sheets("Diametro").visible = True
Sheets("Diametro").Select
Case "btn3"
Sheets("UnaTuberia").visible = True
Sheets("UnaTuberia").Select
Case "btn4"
Sheets("TuberiaSerie").visible = True
Sheets("TuberiaSerie").Select
Case "btn5"
Sheets("TuberiaParalelo").visible = True
Sheets("TuberiaParalelo").Select
Case "btn6"
Sheets("Desarenador").visible = True
Sheets("Desarenador").Select
Formulas_I.Iterar_VI
Case "btn7"
Sheets("Alcantarillados").visible = True
Sheets("Alcantarillados").Select
Case Else
MsgBox "Button """ & control.id & """ clicked" & vbCrLf & _
"Es wurde auf Button """ & control.id & """ in Ribbon geklickt", _
vbInformation

94
End Select
End Sub

'Command Button

Sub OnActionButtonHelp(control As IRibbonControl, ByRef CancelDefault)


' Callbackname in XML File Command "onAction"

' Callback for command event button click


' Callback fuer Command Button Click

MsgBox "Button ""Help"" clicked" & vbCrLf & _


"Es wurde auf Button ""Hilfe"" geklickt", _
vbInformation
CancelDefault = True

End Sub

Sub OnActionCheckBox(control As IRibbonControl, _


pressed As Boolean)
' Callbackname in XML File "OnActionCheckBox"

' Callback for event checkbox click


' Callback für Checkbox Click

Select Case control.id


'Case "chkMyCheckbox"

95
' If pressed = True Then
'
' Else
'
' End If
'
Case Else
MsgBox "The Value of the Checkbox """ & control.id & """ is: " & pressed & vbCrLf & _
"Der Wert der Checkbox """ & control.id & """ ist: " & pressed, _
vbInformation
End Select

End Sub
Sub GetPressedCheckBox(control As IRibbonControl, _
ByRef bolReturn)

' Callbackname in XML File "GetPressedCheckBox"

' Callback for checkbox


' indicates how the control is displayed
' Callback für Checkbox wie das Control
' angezeigt werden soll

Select Case control.id


Case Else
If getTheValue(control.Tag, "DefaultValue") = "1" Then

96
bolReturn = True
Else
bolReturn = False
End If
End Select

End Sub

Sub OnActionTglButton(control As IRibbonControl, _


pressed As Boolean)

' Callbackname in XML File "onAction"


' Callback für einen Toggle Button Klick
' Callback for a Toggle Buttons click event

Select Case control.id


' If pressed = True Then
'
' Else
'
' End If
Case Else
MsgBox "The Value of the Toggle Button """ & control.id & """ is: " & pressed & vbCrLf & _
"Der Wert der Toggle Button """ & control.id & """ ist: " & pressed, _
vbInformation

97
End Select

End Sub

Sub GetPressedTglButton(control As IRibbonControl, _


ByRef pressed)
' Callbackname in XML File "getPressed"

' Callback für ein Access ToogleButton Control wie dieser Angezeigt werden soll
' Callback for an Access ToogleButton Control. Indicates how the control is displayed

Select Case control.id


Case Else
If getTheValue(control.Tag, "DefaultValue") = "1" Then
pressed = True
Else
pressed = False
End If
End Select
End Sub

Public Sub GetEnabled(control As IRibbonControl, ByRef enabled)


' Callbackname in XML File "getEnabled"

' To set the property "enabled" to a Ribbon Control


' For further information see: http://www.accessribbon.de/en/index.php?Downloads:12
' Setzen der Enabled Eigenschaft eines Ribbon Controls

98
' Weitere Informationen: http://www.accessribbon.de/index.php?Downloads:12

Select Case control.id


'Case "ID_XMLRibbControl"
' enabled = bolEnabled
Case Else
enabled = True
End Select
End Sub

Public Sub GetVisible(control As IRibbonControl, ByRef visible)


' Callbackname in XML File "getVisible"
' To set the property "visible" to a Ribbon Control
' For further information see: http://www.accessribbon.de/en/index.php?Downloads:12
' Setzen der Visible Eigenschaft eines Ribbon Controls
' Weitere Informationen: http://www.accessribbon.de/index.php?Downloads:12

Select Case control.id


'Case "ID_XMLRibbControl"
' visible = bolVisible
Case Else
visible = True
End Select
End Sub

Sub GetLabel(control As IRibbonControl, ByRef label)

99
' Callbackname in XML File "getLabel"
' To set the property "label" to a Ribbon Control

Select Case control.id


'Case "ID_XMLRibbControl"
' label = "My Label Text"
Case Else
label = "*getLabel*"

End Select

End Sub
'EditBox

Sub GetTextEditBox(control As IRibbonControl, _


ByRef strText)
' Callbackname in XML File "GetTextEditBox"

' Callback für EditBox welcher Wert in der


' EditBox eingetragen werden soll.
' Callback for an EditBox Control
' Indicates which value is to set to the control

Select Case control.id


Case Else

100
strText = getTheValue(control.Tag, "DefaultValue")
End Select

End Sub

Sub OnChangeEditBox(control As IRibbonControl, _


strText As String)
' Callbackname in XML File "OnChangeEditBox"

' Callback Editbox: Rückgabewert der Editbox


' Callback Editbox: Return value of the Editbox

Select Case control.id


'Case "MyEbx"
'If strText = "Password" Then
'
'End If
Case Else
MsgBox "The Value of the EditBox """ & control.id & """ is: " & strText & vbCrLf & _
"Der Wert der EditBox """ & control.id & """ ist: " & strText, _
vbInformation
End Select

End Sub

'DropDown

101
Sub OnActionDropDown(control As IRibbonControl, _
selectedId As String, _
selectedIndex As Integer)
' Callbackname in XML File "OnActionDropDown"

' Callback onAction (DropDown)

Select Case control.id


'Case "MyItemID"
'
Case Else
MsgBox "The selected ItemID of DropDown-Control """ & control.id & """ is : """ & selectedId & """" & vbCrLf &
_
"Die selektierte ItemID des DropDown-Control """ & control.id & """ ist : """ & selectedId & """", _
vbInformation
End Select

End Sub

Sub GetSelectedItemIndexDropDown(control As IRibbonControl, _


ByRef index)
' Callbackname in XML File "GetSelectedItemIndexDropDown"

' Callback getSelectedItemIndex (DropDown)

Dim varIndex As Variant


varIndex = getTheValue(control.Tag, "DefaultValue")

102
If IsNumeric(varIndex) Then
Select Case control.id
Case Else
index = varIndex
End Select
End If

End Sub

'Gallery

Sub OnActionGallery(control As IRibbonControl, _


selectedId As String, _
selectedIndex As Integer)
' Callbackname in XML File "OnActionGallery"

' Callback onAction (Gallery)

Select Case control.id


'Case "MyGalleryID"
' Select Case selectedId
' Case "MyGalleryItemID"
'
Case Else
Select Case selectedId
Case Else

103
MsgBox "The selected ItemID of Gallery-Control """ & control.id & """ is : """ & selectedId & """" & vbCrLf
&_
"Die selektierte ItemID des Gallery-Control """ & control.id & """ ist : """ & selectedId & """", _
vbInformation
End Select
End Select

End Sub

Sub GetSelectedItemIndexGallery(control As IRibbonControl, _


ByRef index)
' Callbackname in XML File "GetSelectedItemIndexGallery"
' Callback getSelectedItemIndex (Gallery)

Dim varIndex As Variant


varIndex = getTheValue(control.Tag, "DefaultValue")

If IsNumeric(varIndex) Then
Select Case control.id

Case Else
index = varIndex

End Select

End If

104
End Sub

'Combobox

Sub GetTextComboBox(control As IRibbonControl, _


ByRef strText)

' Callbackname im XML File "GetTextComboBox"

' Callback getText (Combobox)

Select Case control.id


Case Else
strText = getTheValue(control.Tag, "DefaultValue")
End Select

End Sub

Sub OnChangeComboBox(control As IRibbonControl, _


strText As String)

' Callbackname im XML File "OnChangeCombobox"

' Callback onChange (Combobox)

105
Select Case control.id

Case Else
MsgBox "The selected Item of Combobox-Control """ & control.id & """ is : """ & strText & """" & vbCrLf & _
"Das selektierte Item des Combobox-Control """ & control.id & """ ist : """ & strText & """", _
vbInformation
End Select

End Sub

' DynamicMenu
Sub GetContent(control As IRibbonControl, _
ByRef XMLString)

' Sample for a Ribbon XML "getContent" Callback


' See also http://www.accessribbon.de/en/index.php?Access_-_Ribbons:Callbacks:dynamicMenu_-_getContent
' and: http://www.accessribbon.de/en/index.php?Access_-_Ribbons:Ribbon_XML___Controls:Dynamic_Menu

' Beispiel fuer einen Ribbon XML - "getContent" Callback


' Siehe auch: http://www.accessribbon.de/index.php?Access_-_Ribbons:Callbacks:dynamicMenu_-_getContent
' und : http://www.accessribbon.de/?Access_-_Ribbons:Ribbon_XML___Controls:Dynamic_Menu

Select Case control.id

106
Case Else
XMLString = getXMLForDynamicMenu()
End Select

End Sub

' Helper Function


' Hilfsfunktionen

Public Function getXMLForDynamicMenu() As String

' Creates a XML String for DynamicMenu CallBack - getContent


' Erstellt den Inhalt fuer das DynamicMenu im Callback getContent

Dim lngDummy As Long


Dim strDummy As String
Dim strContent As String

Dim Items(4) As ItemsVal


Items(0).id = "btnDy1"
Items(0).label = "Item 1"
Items(0).imageMso = "_1"
Items(1).id = "btnDy2"
Items(1).label = "Item 2"
Items(1).imageMso = "_2"

107
Items(2).id = "btnDy3"
Items(2).label = "Item 3"
Items(2).imageMso = "_3"
Items(3).id = "btnDy4"
Items(3).label = "Item 4"
Items(3).imageMso = "_4"
Items(4).id = "btnDy5"
Items(4).label = "Item 5"
Items(4).imageMso = "_5"

strDummy = "<menu xmlns=""http://schemas.microsoft.com/office/2006/01/customui"">" & vbCrLf

For lngDummy = LBound(Items) To UBound(Items)


strContent = strContent & _
"<button id=""" & Items(lngDummy).id & """" & _
" label=""" & Items(lngDummy).label & """" & _
" imageMso=""" & Items(lngDummy).imageMso & """" & _
" onAction=""OnActionButton""/>" & vbCrLf
Next

strDummy = strDummy & strContent & "</menu>"


getXMLForDynamicMenu = strDummy

End Function

Public Function getTheValue(strTag As String, strValue As String) As String

108
' *************************************************************
' Erstellt von : Avenius
' Parameter : Input String, SuchValue String
' Erstellungsdatum : 05.01.2008
' Bemerkungen :
' Änderungen :
'
' Beispiel
' getTheValue("DefaultValue:=Test;Enabled:=0;Visible:=1", "DefaultValue")
' Return : "Test"
' *************************************************************

On Error Resume Next


Dim workTb() As String
Dim Ele() As String
Dim myVariabs() As String
Dim I As Integer

workTb = Split(strTag, ";")

ReDim myVariabs(LBound(workTb) To UBound(workTb), 0 To 1)


For I = LBound(workTb) To UBound(workTb)
Ele = Split(workTb(I), ":=")
myVariabs(I, 0) = Ele(0)
If UBound(Ele) = 1 Then
myVariabs(I, 1) = Ele(1)

109
End If
Next

For I = LBound(myVariabs) To UBound(myVariabs)


If strValue = myVariabs(I, 0) Then
getTheValue = myVariabs(I, 1)
End If
Next

End Function

'################################################################
'# #
'# Created with / Erstellt mit: #
'# IDBE Ribbon Creator #
'# Version 1.1034 #
'# #
'# (c) 2009-2010 IDBE Avenius #
'# #
'# http://www.ribboncreator.com #
'# http://www.ribboncreator2010.com #
'# http://www.accessribon.com #
'# http://www.avenius.com #
'# #
'# You may send change requests or report errors to: #
'# Aenderungswuensche oder Fehler bitte an: #
'# #

110
'# mailto://[email protected] #
'# #
'################################################################
Módulos (Formatos_Especiales)

Private Sub KillTheForm()


Unload Presentacion
End Sub

Public Function NombreHoja(ref) As String


Application.Volatile True
NombreHoja = ref.Parent.Name
End Function

Public Sub Borrar()

111
ActiveWindow.Zoom = 90
Cells.Select
With Selection
.ClearContents
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = False
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
.PatternTintAndShade = 0
End With
With Selection.Font
.Name = "Arial"
.FontStyle = "Normal"
.Size = 10
.Strikethrough = False
.Subscript = False
.OutlineFont = False

112
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
With Selection
.Borders(xlDiagonalDown).LineStyle = xlNone
.Borders(xlDiagonalUp).LineStyle = xlNone
.Borders(xlEdgeLeft).LineStyle = xlNone
.Borders(xlEdgeTop).LineStyle = xlNone
.Borders(xlEdgeBottom).LineStyle = xlNone
.Borders(xlEdgeRight).LineStyle = xlNone
.Borders(xlInsideVertical).LineStyle = xlNone
.Borders(xlInsideHorizontal).LineStyle = xlNone
End With
Range("A1").Select
End Sub

Public Sub AutoAjustar(Vista, A As Variant)


ActiveWindow.Zoom = Vista
Cells.Select
With Selection.Interior
'.ColorIndex = 2
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With

113
Cells.EntireColumn.AutoFit
Cells.EntireRow.AutoFit
'Columns("B:E").Select
'Selection.ColumnWidth = A
Range("A1").Select
End Sub

Sub Formato_Celda()
Selection.Borders(xlEdgeLeft).ColorIndex = xlAutomatic
Selection.Borders(xlEdgeTop).LineStyle = xlContinuous
Selection.Borders(xlEdgeBottom).LineStyle = xlContinuous
Selection.Borders(xlEdgeRight).LineStyle = xlContinuous
Selection.NumberFormat = "0"
Selection.Interior.ThemeColor = xlThemeColorDark1
Selection.Interior.TintAndShade = -0.05

Selection.Font.Bold = True
Selection.Font.Italic = True
End Sub

Sub Insertar_Fila(Fila As Variant)


ActiveCell.Offset(Fila, 0).Range("A1:Z1").Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
End Sub

114
Módulos (Formulas_I)

Public Function NR(Q, d As Variant, Optional v As Variant = 0.00000114) As Variant


Application.Volatile True
Pi = 4 * Atn(1) '3.14159
NR = (4 * Abs(Q)) / (v * Pi * d)
End Function

Public Function NR_v(v, d As Variant, Optional visc As Variant = 0.00000114) As Variant


Application.Volatile True
Pi = 4 * Atn(1) '3.14159
NR_v = v * d / visc

115
End Function

Public Function Darcy(Optional eD As Variant = 0, Optional NR As Variant = 1E+300) As Variant


Application.Volatile True
eD = Abs(eD)
NR = Abs(NR)
If (NR <= 2100) Then
Darcy = Array(64 / NR, 0, 0)
Else
n=0
X0 = -(2 / Log(10#)) * Log(eD / (10 ^ 0.57) + (10 ^ 0.71) / (NR ^ 0.89))
Do
X1 = -(2 / Log(10#)) * Log(eD / (10 ^ 0.57) + (10 ^ 0.4) * X0 / NR)
If (Abs(X1 - X0) <= 0.000000000000001) Then Exit Do
X0 = X1
n=n+1
Loop Until (n >= 100)
Darcy = Array((1 / X1) ^ 2, Abs(X0 - X1), n)
End If
End Function

Public Function Hf(f, L, d, Q As Variant, Optional g As Variant = 9.81) As Variant


Application.Volatile True
Pi = 4 * Atn(1)
Pi2 = Pi ^ 2
Hf = f * (L / (d ^ 5)) * ((8 * Q * Abs(Q)) / (Pi2 * g))
End Function

116
Public Function Hk(k, d, Q As Variant, Optional g As Variant = 9.81) As Variant
Application.Volatile True
Pi = 4 * Atn(1)
Pi2 = Pi ^ 2
Hk = (k / (d ^ 4)) * ((8 * Q * Abs(Q)) / (Pi2 * g))
End Function

Public Function Hfk(f, L, k, d, Q As Variant, Optional g As Variant = 9.81) As Variant


Application.Volatile True
Hfk = Hf(f, L, d, Q, g) + Hk(k, d, Q, g)
End Function
Public Function Dn(f, L, k, Q, H As Variant, Optional g As Variant = 9.81) As Variant
Application.Volatile True
Pi = 4 * Atn(1)
Pi2 = Pi ^ 2
n=0
d0 = ((8 * f * L * (Q ^ 2)) / (Pi2 * g * H)) ^ (1 / 5)
Do
d1 = d0 * (5 * Hk(k, d0, Q, g) + 6 * Hf(f, L, d0, Q, g) - H) / (4 * Hk(k, d0, Q, g) + 5 * Hf(f, L, d0, Q, g))
If (Abs(d1 - d0) <= 0.000000000000001) Then Exit Do
d0 = d1
n=n+1
Loop Until (n >= 100)
Dn = Array(d1, D3, Abs(d1 - d0), n)
End Function

117
Public Function QV(f, L, k, d, H As Variant, Optional g As Variant = 9.81) As Variant
Application.Volatile True
Pi = 4 * Atn(1)
v = Sqr((2 * g * H * d) / (f * L + k * d))
Q = (Pi / 4) * (d ^ 2) * v
QV = Array(Q, v)
End Function

Public Function Vs_Stokes(rs, r, visc, d As Variant, Optional g As Variant = 981) As Variant


Application.Volatile True
Pi = 4 * Atn(1)
Vs_Stokes = (g / (18 * visc)) * (rs - r) * (d ^ 2)
End Function

Public Function Cd_Newton(NR As Variant) As Variant


Application.Volatile True
Pi = 4 * Atn(1)
If NR < 0.5 Then
Cd_Newton = (24 / NR) + (3 / (NR ^ 0.5)) + 0.34
Else
If (NR >= 0.5 And NR < 2000) Then
Cd_Newton = (24 / NR) + (3 / (NR ^ 0.5)) + 0.34
Else
Cd_Newton = 0.4
End If
End If

118
End Function

Public Function Vs_Newton(rs, r, Cd, d As Variant, Optional g As Variant = 981) As Variant


Application.Volatile True
Pi = 4 * Atn(1)
Vs_Newton = ((4 * g * (rs - r) * d) / (3 * Cd * r)) ^ (1 / 2)
End Function

Public Function Vs_Newton_Iterada(rs, r, visc, d As Variant, Optional g As Variant = 981) As Variant


Application.Volatile True
Pi = 4 * Atn(1)
Reynols = 0.5
Cd = Cd_Newton(Reynols)
V0 = Vs_Newton(rs, r, Cd, d, g)
n=0
Do
Reynols = NR_v(V0, d, visc)
Cd = Cd_Newton(Reynols)
V1 = Vs_Newton(rs, r, Cd, d, g)
If (Abs(V1 - V0) <= 0#) Then Exit Do
V0 = V1
n=n+1
Loop Until (n >= 100)
Vs_Newton_Iterada = Array(V1, Abs(V1 - V0), n)
End Function

Public Function d_Stokes(rs, r, visc, Vs As Variant, Optional g As Variant = 981) As Variant

119
Application.Volatile True
Pi = 4 * Atn(1)
d_Stokes = ((18 * Vs * visc) / (g * (rs - r))) ^ (1 / 2)
End Function

Public Function d_Newton(rs, r, visc, Vs As Variant, Optional g As Variant = 981) As Variant


Application.Volatile True
Reynols = 0.5
Cd = Cd_Newton(Reynols)
d0 = ((3 * Cd * ((Reynols * visc) ^ 2) * r) / (4 * g * (rs - r))) ^ (1 / 3)
n=0
Do
Reynols = NR_v(Vs, d0, visc)
Cd = Cd_Newton(Reynols)
d1 = ((3 * Cd * ((Reynols * visc) ^ 2) * r) / (4 * g * (rs - r))) ^ (1 / 3)
If (Abs(d1 - d0) <= 0#) Then Exit Do
d0 = d1
n=n+1
Loop Until (n >= 100)
d_Newton = Array(d1, Abs(d1 - d0), n, Cd, Reynols)
End Function

Public Function V_Arrastre(k, S, d, f As Variant, Optional g As Variant = 981) As Variant


Application.Volatile True
Pi = 4 * Atn(1)
V_Arrastre = ((8 * k * (S - 1) * g * d) / f) ^ (1 / 2)
End Function

120
Sub Iterar_VI()
With Application
.Iteration = True
.MaxIterations = 1000
.MaxChange = 0.000000001
End With
'Range("E8").Select
'ActiveCell.FormulaR1C1 = "=+2*((3*R[42]C)^(1/3))"
Range("E9").Select
ActiveCell.FormulaR1C1 = "=+ROUND(L/4/5,2)*5"
Range("E10").Select
ActiveCell.FormulaR1C1 = "=+ROUND(B/1.5/5,2)*5"
'Range("H28").Select
'ActiveCell.FormulaR1C1 = "=+R[1]C"
'Range("H29").Select
'ActiveCell.FormulaR1C1 = "=+MIN(R[4]C[-3],R[15]C[-3])"
End Sub

Private Function Funcion(x, Q, n, S, d0 As Variant) As Variant


Application.Volatile True
Pi = 4 * Atn(1)
f = (Q * n / Sqr(S)) / d0 ^ (8 / 3) - 1 / (16 * 2 ^ (1 / 3)) * ((x - Sin(x)) ^ (5 / 3) / x ^ (2 / 3))
Funcion = f
End Function

Private Function FuncionD(x, Q, n, S, d0 As Variant) As Variant

121
Application.Volatile True
Pi = 4 * Atn(1)
Dx = Pi / 648000
fp = (Funcion(x + Dx, Q, n, S, d0) - Funcion(x, Q, n, S, d0)) / Dx
FuncionD = fp
End Function

Public Function AnguloT(Q, n, S, d0 As Variant) As Variant


Application.Volatile True
Pi = 4 * Atn(1)
Contador = 0
X0 = Pi
Do
f = Funcion(X0, Q, n, S, d0)
fp = FuncionD(X0, Q, n, S, d0)
Dx = -f / fp
X1 = X0 + Dx
If (Abs(X0 - X1) <= 0.000000000000001) Then Exit Do
X0 = X1
Contador = Contador + 1
Loop Until (n >= 100)
AnguloT = X1
End Function

Public Function TraerValor(ByVal Referencia, Celda As String) As Double


Application.Volatile True
TraerValor = Worksheets(Referencia).Range(Celda).Value

122
End Function
Módulos (Formulas_Viscosidad_Cinematica)

Public Function Visc_Cinematica(Temperatura As Variant) As Variant


Application.Volatile True
Dim x, y, xn, Exponentes As Variant

y = Array(1.787, 1.519, 1.307, 1.004, 0.801, 0.658, 0.553, 0.475, 0.413, 0.365, 0.326, 0.294)

x = Array( _
Array(0 ^ 1, 5 ^ 1, 10 ^ 1, 20 ^ 1, 30 ^ 1, 40 ^ 1, 50 ^ 1, 60 ^ 1, 70 ^ 1, 80 ^ 1, 90 ^ 1, 100 ^ 1), _
Array(0 ^ 2, 5 ^ 2, 10 ^ 2, 20 ^ 2, 30 ^ 2, 40 ^ 2, 50 ^ 2, 60 ^ 2, 70 ^ 2, 80 ^ 2, 90 ^ 2, 100 ^ 2), _
Array(0 ^ 3, 5 ^ 3, 10 ^ 3, 20 ^ 3, 30 ^ 3, 40 ^ 3, 50 ^ 3, 60 ^ 3, 70 ^ 3, 80 ^ 3, 90 ^ 3, 100 ^ 3), _

123
Array(0 ^ 4, 5 ^ 4, 10 ^ 4, 20 ^ 4, 30 ^ 4, 40 ^ 4, 50 ^ 4, 60 ^ 4, 70 ^ 4, 80 ^ 4, 90 ^ 4, 100 ^ 4), _
Array(0 ^ 5, 5 ^ 5, 10 ^ 5, 20 ^ 5, 30 ^ 5, 40 ^ 5, 50 ^ 5, 60 ^ 5, 70 ^ 5, 80 ^ 5, 90 ^ 5, 100 ^ 5), _
Array(0 ^ 6, 5 ^ 6, 10 ^ 6, 20 ^ 6, 30 ^ 6, 40 ^ 6, 50 ^ 6, 60 ^ 6, 70 ^ 6, 80 ^ 6, 90 ^ 6, 100 ^ 6), _
Array(0 ^ 7, 5 ^ 7, 10 ^ 7, 20 ^ 7, 30 ^ 7, 40 ^ 7, 50 ^ 7, 60 ^ 7, 70 ^ 7, 80 ^ 7, 90 ^ 7, 100 ^ 7), _
Array(0 ^ 8, 5 ^ 8, 10 ^ 8, 20 ^ 8, 30 ^ 8, 40 ^ 8, 50 ^ 8, 60 ^ 8, 70 ^ 8, 80 ^ 8, 90 ^ 8, 100 ^ 8), _
Array(0 ^ 9, 5 ^ 9, 10 ^ 9, 20 ^ 9, 30 ^ 9, 40 ^ 9, 50 ^ 9, 60 ^ 9, 70 ^ 9, 80 ^ 9, 90 ^ 9, 100 ^ 9), _
Array(0 ^ 10, 5 ^ 10, 10 ^ 10, 20 ^ 10, 30 ^ 10, 40 ^ 10, 50 ^ 10, 60 ^ 10, 70 ^ 10, 80 ^ 10, 90 ^ 10, 100 ^ 10), _
Array(0 ^ 11, 5 ^ 11, 10 ^ 11, 20 ^ 11, 30 ^ 11, 40 ^ 11, 50 ^ 11, 60 ^ 11, 70 ^ 11, 80 ^ 11, 90 ^ 11, 100 ^ 11))

xn = Array( _
Array(Temperatura ^ 11), _
Array(Temperatura ^ 10), _
Array(Temperatura ^ 9), _
Array(Temperatura ^ 8), _
Array(Temperatura ^ 7), _
Array(Temperatura ^ 6), _
Array(Temperatura ^ 5), _
Array(Temperatura ^ 4), _
Array(Temperatura ^ 3), _
Array(Temperatura ^ 2), _
Array(Temperatura ^ 1), _
Array(Temperatura ^ 0))

Exponentes = WorksheetFunction.LinEst(y, x)

Visc_Cinematica = (10 ^ -6) * WorksheetFunction.index(WorksheetFunction.MMult(Exponentes, xn), 1, 1)

124
End Function
Módulos (Iteraciones_Hojas)

'Chequeo del Diametro, Problema Tipo III


Sub Calcular_II()
Celda = ActiveCell.Address
ActiveWindow.Zoom = 80

With Application
.Iteration = True
.MaxIterations = 1000
.MaxChange = 0.000000001
End With

125
Range("D17").Select
ActiveCell.FormulaR1C1 = "=+(25.4/1000)*R[-3]C"
Range("D17").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("D18").Select
ActiveCell.FormulaR1C1 = "=+R[-1]C[4]"
Range("D18").Select
ActiveCell.FormulaR1C1 = "=+RC[4]"
Range("D17").Select
ActiveCell.FormulaR1C1 = "=+R[1]C[4]"
Range("D17").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("D18").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=+R[-1]C[4]"
Range(Celda).Select

With Application
.Iteration = False
.MaxIterations = 100
.MaxChange = 0.001
End With

126
End Sub

'Calculo de Caudal, Una (1) Tuberia, Problema Tipo II


Sub Calcular_III()
Celda = ActiveCell.Address
ActiveWindow.Zoom = 80

With Application
.Iteration = True
.MaxIterations = 1000
.MaxChange = 0.000000001
End With
Range("D18").Select
ActiveCell.FormulaR1C1 = "=+Darcy(eD)"
Range("E18:F18").Select
Selection.FormulaArray = "=+QV(RC[-1],L,K,D,H)"
Range("G18").Select
ActiveCell.FormulaR1C1 = "=+NR(RC[-2],D,n)"

Range("D19:G19").Select
Selection.ClearContents
Range("D19").Select
ActiveCell.FormulaR1C1 = "=+Darcy(eD,R[-1]C[3])"
Range("E18:G18").Select
Selection.Copy
Range("E19").Select

127
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Range("D19").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=+Darcy(eD,RC[3])"
Range("D19").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
With Application
.Iteration = False
.MaxIterations = 100
.MaxChange = 0.001
End With
Range(Celda).Select
End Sub

'Calculo de Caudal, Dos (2) Tuberia, Problema Tipo II


Sub Calcular_IV()
Celda = ActiveCell.Address
ActiveWindow.Zoom = 80

Range("N12:N100").Select
Selection.Copy

Range("H12").Select

128
For n = 0 To 100
If (Range("M13").Value = 0.00000000005) Then Exit For
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
CIteracion = n
Next n
Application.CutCopyMode = False
Range("A1").Select
ActiveCell.FormulaR1C1 = "Ireración " & CIteracion
'Range(Celda).Select
End Sub

'Calculo de Caudal, Tres (3) Tuberia, Problema Tipo II


Sub Calcular_V()
Celda = ActiveCell.Address
ActiveWindow.Zoom = 80

Range("H24").Select
ActiveCell.FormulaR1C1 = "=+1/100"
Range("H25").Select
ActiveCell.FormulaR1C1 = "=+2/100"
Range("H26").Select
Range("H34").Select
ActiveCell.FormulaR1C1 = "=+1/100"
Range("H35").Select
ActiveCell.FormulaR1C1 = "=-1/100"
Range("H36").Select

129
Range("H44").Select
ActiveCell.FormulaR1C1 = "=-2/100"
Range("H45").Select
ActiveCell.FormulaR1C1 = "=-1/100"
Range("H46").Select

Range("N23:N123").Select
Selection.Copy

Range("H23").Select
For n = 0 To 100
SE = Abs(Range("M24").Value) + Abs(Range("M34").Value) + Abs(Range("M44").Value)
If (SE <= 0) Then Exit For
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
CIteracion = n
Next n
Application.CutCopyMode = False
Range("A1").Select
ActiveCell.FormulaR1C1 = "Ireración " & CIteracion
Range(Celda).Select
End Sub

'Calculo Desarenador
Sub Calcular_VI()
Celda = ActiveCell.Address
ActiveWindow.Zoom = 60

130
With Application
.Iteration = True
.MaxIterations = 1000
.MaxChange = 0.000000001
End With
Range("E8").Select
ActiveCell.FormulaR1C1 = "=2*((3*R[42]C)^(1/3))"
Range("E9").Select
ActiveCell.FormulaR1C1 = "=+ROUND(L/4/5,2)*5"
Range("E10").Select
ActiveCell.FormulaR1C1 = "=+ROUND(B/1.5/5,2)*5"
Range(Celda).Select
End Sub
Módulos (RelacionesHidraulicas)

Public Function y_do(Angulo As Variant) As Variant


Application.Volatile True
Pi = 4 * Atn(1)
y_do = (1 / 2) * (1 - Cos(Angulo / 2))
End Function

Public Function PerimetroMojadoT(Angulo, d0 As Variant) As Variant


Application.Volatile True
Pi = 4 * Atn(1)
PerimetroMojadoT = Angulo * d0 / 2

131
End Function

Public Function AreaT(Angulo, d0 As Variant) As Variant


Application.Volatile True
Pi = 4 * Atn(1)
AreaT = (1 / 8) * (Angulo - Sin(Angulo)) * (d0 ^ 2)
End Function

Public Function RadioHidraulicoT(Angulo, d0 As Variant) As Variant


Application.Volatile True
Pi = 4 * Atn(1)
RadioHidraulicoT = (1 / 4) * (1 - Sin(Angulo) / Angulo) * d0
End Function
Public Function DistanciaEntreHorillas(Angulo, d0 As Variant) As Variant
Application.Volatile True
Pi = 4 * Atn(1)
DistanciaEntreHorillas = Sin(Angulo / 2) * d0
End Function

Public Function ProfundidadHidraulica(Angulo, d0 As Variant) As Variant


Application.Volatile True
Pi = 4 * Atn(1)
ProfundidadHidraulica = (1 / 8) * ((Angulo - Sin(Angulo)) / Sin(Angulo / 2)) * d0
End Function

Public Function CaudalQ(Angulo, n, S, d0 As Variant) As Variant

132
Application.Volatile True
Pi = 4 * Atn(1)
CaudalQ = (1 / n) * AreaT(Angulo, d0) * (RadioHidraulicoT(Angulo, d0) ^ (2 / 3)) * Sqr(S)
End Function

Public Function CaudalQo(n, S, d0 As Variant) As Variant


Application.Volatile True
Pi = 4 * Atn(1)
CaudalQo = (1 / n) * AreaT(2 * Pi, d0) * (RadioHidraulicoT(2 * Pi, d0) ^ (2 / 3)) * Sqr(S)
End Function

Public Function VelocidadV(Angulo, n, S, d0 As Variant) As Variant


Application.Volatile True
Pi = 4 * Atn(1)
VelocidadV = (1 / n) * (RadioHidraulicoT(Angulo, d0) ^ (2 / 3)) * Sqr(S)
End Function

Public Function VelocidadVo(n, S, d0 As Variant) As Variant


Application.Volatile True
Pi = 4 * Atn(1)
VelocidadVo = (1 / n) * (RadioHidraulicoT(2 * Pi, d0) ^ (2 / 3)) * Sqr(S)
End Function

Public Function DiametroMinimo_d0(Q, n, S As Variant) As Variant


Application.Volatile True
Pi = 4 * Atn(1)
DiametroMinimo_d0 = (((8 * 2 ^ (1 / 3)) / Pi) ^ (3 / 8)) * ((Q * n / Sqr(S)) ^ (3 / 8))

133
End Function
Módulos (SolverI)

Sub SolverEjecutar()

With Application
.Iteration = True
.MaxIterations = 1000
.MaxChange = 0.000000001
End With

Celda = ActiveCell.Address
Range("E8").Select

134
ActiveCell.FormulaR1C1 = "=+2*((3*R[42]C)^(1/3))"
Range("E9").Select
ActiveCell.FormulaR1C1 = "=+ROUND(L/4/5,2)*5"
Range("E10").Select
ActiveCell.FormulaR1C1 = "=+ROUND(B/1.5/5,2)*5"

SolverRestablecer

SolverAgregar referenciaCelda:="$E$11", relación:=1, Formula:="+5"


SolverAgregar referenciaCelda:="$E$11", relación:=3, Formula:="+1"

SolverAgregar referenciaCelda:="$E$12", relación:=1, Formula:="+5"


SolverAgregar referenciaCelda:="$E$12", relación:=3, Formula:="+3"
SolverAgregar referenciaCelda:="$E$33", relación:=3, Formula:="$H$28"
SolverAgregar referenciaCelda:="$E$33", relación:=3, Formula:="$H$29"

SolverAgregar referenciaCelda:="$E$44", relación:=3, Formula:="$H$28"


SolverAgregar referenciaCelda:="$E$44", relación:=3, Formula:="$H$29"

SolverAgregar referenciaCelda:="$E$46", relación:=1, Formula:="+4"


SolverAgregar referenciaCelda:="$E$46", relación:=3, Formula:="+0.5"

SolverAgregar referenciaCelda:="$E$50", relación:=1, Formula:="V"


SolverAgregar referenciaCelda:="$E$61", relación:=1, Formula:="V"

SolverAgregar referenciaCelda:="$E$51", relación:=1, Formula:="As"

135
SolverAgregar referenciaCelda:="$E$62", relación:=1, Formula:="As"

SolverAgregar referenciaCelda:="$E$54", relación:=1, Formula:="+80"


SolverAgregar referenciaCelda:="$E$65", relación:=1, Formula:="+80"

SolverAgregar referenciaCelda:="$E$54", relación:=3, Formula:="+15"


SolverAgregar referenciaCelda:="$E$65", relación:=3, Formula:="+15"

SolverAgregar referenciaCelda:="$E$55", relación:=1, Formula:="+20*$E$36"


SolverAgregar referenciaCelda:="$E$66", relación:=1, Formula:="+20*$E$36"

SolverAgregar referenciaCelda:="$E$56", relación:=1, Formula:="$E$35"


SolverAgregar referenciaCelda:="$E$57", relación:=1, Formula:="$E$35"
SolverAgregar referenciaCelda:="$E$67", relación:=1, Formula:="$E$35"
SolverAgregar referenciaCelda:="$E$68", relación:=1, Formula:="$E$35"

SolverAgregar referenciaCelda:="$E$78", relación:=3, Formula:="$E$55"


SolverAgregar referenciaCelda:="$E$83", relación:=3, Formula:="$E$66"

SolverAgregar referenciaCelda:="$E$9", relación:=3, Formula:="+1/100"


SolverAgregar referenciaCelda:="$E$10", relación:=3, Formula:="+1/100"
SolverAgregar referenciaCelda:="$E$8", relación:=3, Formula:="+1/100"

SolverOpciones tiempoMáximo:=1000, Iteraciones:=1000, Precision:=5E-50, _


estimaciónLineal:=False, valorLógicoPresentar:=False, estimación:=1, _
derivaciones:=1, buscar:=1, tolerancia:=5, escala:=False, convergencia:=0.0001 _
, asumirNoNegativo:=True

136
SolverAceptar definirCelda:="$E$25", valorMáxMín:=2, valorDe:="0", _
celdasCambiantes:="$E$8:$E$10"

SolverResolver

'SolverRestablecer

Range(Celda).Select

End Sub

You might also like