¿Cómo sumar 2 label y 2 textbox,y mostrar suma en un 3er label?

Estoy haciendo un formulario en excel 2007, con un combobox que filtra, dos label que muestra datos del filtro, y dos text box, en la cual agrego o resto. Tanto en los dos labels como en los dos textbox se maneja con números.
Cómo hacer que en un tercer label me muestre la suma de los 2 label mas los 2 textbox, que al introducir un dato en un textbox se actualice el tercer label. Adjunto la macro;
Formulario:
-----------------------------------------------------
Private Sub cbo_Agencias_change()
If nAgencia(cbo_Agencias.Text) <> 0 Then
Sheets("Hoja1").Activate
Cells(cbo_Agencias.ListIndex + 4, 1).Select
lb_PLANCHAS = ActiveCell.Offset(0, 4)
lb_SUELTOS = ActiveCell.Offset(0, 5)
Else
txt_PLANCHAS = ""
txt_SUELTOS = ""
End If
End Sub
--------------------------------------------------------
Sub LimpiarFormulario()
cbo_Agencias = ""
txt_PLANCHAS = ""
txt_SUELTOS = ""
lb_PLANCHAS = ""
lb_SUELTOS = ""
lb_TOTAL = ""
End Sub
------------------------------------------------------------
Private Sub cmd_Agregar_Click()
Dim i As Integer
If cbo_Agencias.Text = "" Then
MsgBox "Agencia inválida", vbInformation + vbOKOnly
cbo_Agencias.SetFocus
Exit Sub
End If
Sheets("Hoja1").Activate
Dim fAgencia As Integer
fAgencia = nAgencia(cbo_Agencias.Text)
If fAgencia = 0 Then
Do While Not IsEmpty(ActiveCell)
ActiveCell.Offset(1, 0).Activate ' si el registro no existe, se va al final.
Loop
Else
Cells(fAgencia, 1).Select ' cuando ya existe el registro, cumple esta condición.
End If
'Aquí es cuando agregamos o modificamos el registro
Application.ScreenUpdating = False
ActiveCell = cbo_Agencias
ActiveCell.Offset(0, 4) = Val(txt_PLANCHAS.Value) + Val(lb_PLANCHAS)
ActiveCell.Offset(0, 5) = Val(txt_SUELTOS.Value) + Val(lb_SUELTOS)
Application.ScreenUpdating = True
LimpiarFormulario
cbo_Agencias.SetFocus
End Sub
-------------------------------------------------------------------------------------------
Private Sub cmd_FINALIZAR_Click()
End
End Sub
---------------------------------------------------------------------------------------
MODULO:
Option Explicit
------------------------------------------------------------------
Sub carga()
Sheets("Hoja1").Activate
frm_Carga.Show
End Sub
--------------------------------------------------------------------
Function nAgencia(agencias As String) As Integer
Application.ScreenUpdating = False
Sheets("Hoja1").Activate
Range("A4").Activate
nAgencia = 0
Do While Not IsEmpty(ActiveCell)
If agencias = ActiveCell Then
nAgencia = ActiveCell.Row
End If
ActiveCell.Offset(1, 0).Select
Loop
Application.ScreenUpdating = True
End Function
---------------------------------------------------------------------------

1 respuesta

Respuesta
1

Espero estés bien.

Te cuento que la función de suma o resta de dos TextBox es bastante simple. Bastara con que identifiques los nombres e indiques cualquier operación matemática. Por ejemplo:

TextBox4 = TextBox2 * (2 / 100)
TextBox4.Value = Format(Val(TextBox4), "$ #,##.00")

Espero que te sirva.

Bendiciones!

Lucas.

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas