Captura De Datos Para Macros En Excel
Private Sub CommandButton1_Click()
Rem Ubicamos elcursor e insertamos una fila
If TextBox1.Text "" Then
Range("A9").Select
Selection.EntireRow.Insert
Rem Ubicamos el cursoren la celda A9
Range("A9").Select
Rem Insertamos el texto en A9
ActiveCell.FormulaR1C1 = TextBox1
Rem Repetimos con Textbox2 y TextBox3
Range("B9").Select
ActiveCell.FormulaR1C1 =Val(TextBox2)
Range("C9").Select
ActiveCell.FormulaR1C1 = Val(TextBox3)
Rem ubicamos el cursor en la celda D9
Range("D9").Select
ActiveCell.FormulaR1C1 = Val(TextBox2) * Val(TextBox3)
Rem Empty LimpiamosLos TextBox
TextBox1 = Empty
TextBox2 = Empty
TextBox3 = Empty
Rem TextBox1.SetFocus ponemos el cursor en TextBox1
Else
MsgBox "Escriba un producto"
End If
TextBox1.SetFocus
End SubPrivate Sub CommandButton2_Click()
Rem Oculta el formulario
UserForm1.Hide
End Sub
EJEMPLO DE SECUENIAL SIMPLE
Sub SelectivaSimple()
' Poner las casillas donde se guardan los valores 0.ActiveSheet.Range("A1").Value = 0
ActiveSheet.Range("A2").Value = 0
ActiveSheet.Range("A3").Value = 0
ActiveSheet.Range("A1").Value = Val(InputBox("Entrar el precio", "Entrar"))
' Si el valorde la casilla A1 es mayor que 1000, entonces, pedir descuento
If ActiveSheet.Range("A1").Value > 1000 Then
ActiveSheet.Range("A2").Value = Val(InputBox("Entrar Descuento", "Entrar"))
End IfActiveSheet.Range("A3").Value = ActiveSheet.Range("A1").Value - _
ActiveSheet.Range("A2").Value
End Sub
Sub Condicional()
Dim Precio As Integer
Dim Descuento As Integer
Precio = 0
Descuento = 0Precio = Val(InputBox("Entrar el precio", "Entrar"))
' Si el valor de la variable precio es mayor que 1000, entonces, pedir descuento
If Precio > 1000 Then
Descuento = Val(InputBox("EntrarDescuento", "Entrar"))
End If
ActiveSheet.Range("A1").Value = Precio
ActiveSheet.Range("A2").Value = Descuento
ActiveSheet.Range("A3").Value = Precio - Descuento
End Sub
Sub Condicional2()
If...
Regístrate para leer el documento completo.