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.
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.
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.
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