0% found this document useful (0 votes)
32 views1 page

Este Es El Código de La Userform

This document contains code for a userform in VBA. The code initializes the form by filling in textboxes with values from a "Model" worksheet. It also defines click handlers for OK and Cancel buttons - the OK button moves values from the textboxes back to the Model worksheet, then unloads the form, while Cancel simply unloads the form.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views1 page

Este Es El Código de La Userform

This document contains code for a userform in VBA. The code initializes the form by filling in textboxes with values from a "Model" worksheet. It also defines click handlers for OK and Cancel buttons - the OK button moves values from the textboxes back to the Model worksheet, then unloads the form, while Cancel simply unloads the form.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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