You are on page 1of 1

Este es el código de la userform

Option Explicit

Private Sub cmdCancel_Click()


Unload Me
End
End Sub

Private Sub cmdOK_Click()


Dim ctl As Control
' Ubica las alternativas del usuario en la hoja Model.
Range("inv.Inicial").Value = txtBeginningInventory.Text
Range("porcentaje_costAlmacenamiento").Value = txtHoldingCostPercent.Text
For Each ctl In Me.Controls
If TypeName(ctl) = "TextBox" Then
If Left(ctl.Name, 4) = "txtU" Then _
Range("CostoproduccionU").Cells(1, Val(Right(ctl.Name, 1))).Value = ctl.Text
If Left(ctl.Name, 4) = "txtP" Then _
Range("Cap.produccion").Cells(1, Val(Right(ctl.Name, 1))).Value = ctl.Text
If Left(ctl.Name, 4) = "txtS" Then _
Range("capalmacenamiento ").Cells(1, Val(Right(ctl.Name, 1))).Value = ctl.Text
If Left(ctl.Name, 4) = "txtD" Then _
Range("demanda").Cells(1, Val(Right(ctl.Name, 1))).Value = ctl.Text
End If
Next
Unload Me
End Sub

Private Sub UserForm_Initialize()


Dim ctl As Control
' Llena la forma con los valores existents en la hoja Model .
txtBeginningInventory.Text = Range("Beginning_inventory").Value
txtHoldingCostPercent.Text = Range("Holding_cost_percent").Value
For Each ctl In Me.Controls
If TypeName(ctl) = "TextBox" Then
If Left(ctl.Name, 4) = "txtU" Then _
ctl.Text = Range("Unit_production_cost").Cells(1, Val(Right(ctl.Name, 1))).Value
If Left(ctl.Name, 4) = "txtP" Then _
ctl.Text = Range("Production_capacity").Cells(1, Val(Right(ctl.Name, 1))).Value
If Left(ctl.Name, 4) = "txtS" Then _
ctl.Text = Range("Storage_capacity").Cells(1, Val(Right(ctl.Name, 1))).Value
If Left(ctl.Name, 4) = "txtD" Then _
ctl.Text = Range("Demand").Cells(1, Val(Right(ctl.Name, 1))).Value
End If
Next
End Sub

You might also like