Вы находитесь на странице: 1из 12

SESION 4MACROS

EJERCICIO CON DESPLAZAMIENTO DE CELDAS ACTIVAS

Esto te mueve una celda hacia la derecha,

activecell.offset(0,1).activate

si quieres ir a la izquierda sería:

activecell.offset(0,-1).activate

si quieres ir abajo sería:

activecell.offset(1,0).activate

si quieres ir arriba seria:

activecell.offset(-1,0).activate

Private Sub CommandButton1_Click()


Dim cod, des As String
Dim pre, cant, impor As Double
cod = TextBox1
des = TextBox2
pre = TextBox3
cant = TextBox4
Range("A2").Select

ActiveCell.FormulaR1C1 = TextBox1
impor = pre * cant
TextBox5 = impor
ActiveCell.Value = cod
ActiveCell.Offset(0, 1).Activate
ActiveCell.Value = des
ActiveCell.Offset(0, 1).Activate
ActiveCell.Value = pre
ActiveCell.Offset(0, 1).Activate
ActiveCell.Value = cant
ActiveCell.Offset(0, 1).Activate
ActiveCell.Value = impor
ActiveCell.Offset(rowOffset:=1, columnOffset:=-4).Activate
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox1.SetFocus
End Sub
Private Sub CommandButton3_Click()
End
End Sub
Sub PRODUCTO()
UserForm2.Show
End Sub

LAZOS
Tema1.-Cargar elementos en un COMBOBoX1

Private Sub ComboBox1_Click()


ActiveCell.Value = ComboBox1
ActiveCell.Offset(1, 0).Select
End Sub

Private Sub UserForm_Activate()


ComboBox1.AddItem "Geometria"
ComboBox1.AddItem "Trigonometria"
ComboBox1.AddItem "Aritmetica"
ComboBox1.Text = "EliaOpcion"
End Sub

Tema2.-Enviar datos a Combo Box

Ahora si deseas tomar información de una celda y enviarla a un


ComboboxoListboxescribe el siguiente código en un Botón:

Private Sub CommandButton1_Click()

Range("a9").Select

Do While ActiveCell<> Empty


ActiveCell.Offset(1, 0).Select
ListBox1.AddItem ActiveCell
Loop

End Sub
Tema3.-AplicacionComboBox

Private Sub ComboBox1_Change()


Label1.Caption = Math.Cos(Val(ComboBox1.Text) * 3.141516 / 180)
End Sub
Private Sub ComboBox1_Click()
ActiveCell.Value = ComboBox1
ActiveCell.Offset(1, 0).Select
End Sub
Private Sub CMDNUEVO_Click()
Dim DEMANDA, ANGULO, FP, VOLTAJE, CORRIENTE As Double
DEMANDA = TextBox1
ANGULO = ComboBox2.Text
FP = Label5.Caption
CORRIENTE = Label7.Caption
ActiveCell.Value = ANGULO
ActiveCell.Offset(0, 1).Activate
ActiveCell.Value = Format(FP, "#0.00")
ActiveCell.Offset(0, 1).Activate
ActiveCell.Value = DEMANDA
ActiveCell.Offset(0, 1).Activate
ActiveCell.Value = CORRIENTE
ActiveCell.Offset(rowOffset:=1, columnOffset:=-3).Activate
TextBox1.Text = ""
ComboBox2.Text = ""
Label5.Caption = ""
Label7.Caption = ""
TextBox1.SetFocus
End Sub
Private Sub ComboBox2_Change()
Label5.Caption = Math.Cos(Val(ComboBox2.Text) * 3.141516 / 180)
Label7.Caption = Format(Val(TextBox1.Text) / (Math.Sqr(3) * 440 * Label5.Caption),
"##.00")
End Sub
Private Sub UserForm_Activate()
For I = 0 To 360 Step 5
ComboBox2.AddItem (I)
Next
Range("b2").Select
End Sub
Tema4.-ListBox y ComboBox

Private Sub ListBox1_Click()


Dim V, I, R2 As Single
V = Val(ComboBox1.Text)
R2 = Val(ListBox1.Text)
Label5.Caption = Format(V / (R2 + 30), "#0.00")
End Sub

Private Sub UserForm_Activate()


Dim I, J As Integer
For I = 0 To 220 Step 10
ComboBox1.AddItem (I)
Next
ComboBox1.Text = 0
For J = 10 To 5000 Step 100
ListBox1.AddItem (J)
Next
End Sub
Tema.ListBox-ComboBox

Private Sub ComboBox1_Change()


Select Case ComboBox1.ListIndex
Case 0
ListBox1.Clear
ListBox1.AddItem ("DIODO SIMPLE")
ListBox1.AddItem ("DIODO ZENER")
ListBox1.AddItem ("DIODO LED")
Case 1
ListBox1.Clear
ListBox1.AddItem ("BJT")
ListBox1.AddItem ("FET")
ListBox1.AddItem ("MOSFET")
Case 2
ListBox1.Clear
ListBox1.AddItem ("OPERACIONAL")
ListBox1.AddItem ("POTENCIA")

End Select

End Sub

Private Sub CommandButton1_Click()

ActiveCell.Value = ComboBox1.Text
ActiveCell.Offset(0, 1).Activate
ActiveCell.Value = ListBox1.Text
ActiveCell.Offset(0, 1).Activate
ActiveCell.Offset(rowOffset:=1, columnOffset:=-2).Activate

End Sub

Private Sub UserForm_Activate()


ComboBox1.AddItem ("DIODOS")
ComboBox1.AddItem ("TRANSISTORES")
ComboBox1.AddItem ("AMPLIFICADORES")
ComboBox1.Text = "DIODOS"
End Sub
EJEMPLO CON CUADRO DE DEUDAS
Private Sub CmCuotas_Click()

Dim p, i, n, amort, interes, cuotas As Double

Dim Sinteres, Samort, ScuotasAs Double

Dim fila As Integer

p = TextBox1

i = Val(TextBox2) / 100

n = TextBox3

Range("D3").Value = p

Range("D4").Value = i

Range("D5").Value = n

cuotas = p * ((i * (1 + i) ^ n) / ((1 + i) ^ n - 1))

Sinteres = 0: Samort = 0: Scuotas = 0

fila = 1

While fila<= n

interes = p * i

amort = cuotas - interes

Cells(fila + 9, 2) = fila

Cells(fila + 9, 3).Value = p

Cells(fila + 9, 4).Value = interes

Cells(fila + 9, 5).Value = amort

Cells(fila + 9, 6).Value = cuotas

p = p - amort

Sinteres = Sinteres + interes

Samort = Samort + amort

Scuotas = Scuotas + cuotas

fila = fila + 1

Wend

Cells(fila + 9, 3).Value = "Totales"

Cells(fila + 9, 4).Value = Sinteres


Cells(fila + 9, 5).Value = Samort

Cells(fila + 9, 6).Value = Scuotas

Range(Cells(10, 3), Cells(fila + 9, 6)).NumberFormat = "#,##0.00"

Range(Cells(fila + 9, 2), Cells(fila + 9, 6)).Select

Selection.Interior.ColorIndex = 1

Selection.Font.Bold = True

Selection.Font.ColorIndex = 2

End Sub

Private Sub CmdNuevo_Click()

Dim f As Integer

f = 10

Range("D10").Select

Do Until IsEmpty(ActiveCell.Value)

Range(Cells(f, 2), Cells(f, 6)).Clear

ActiveCell.Offset(1, 0).Select

f=f+1

Loop

TextBox1 = ""

TextBox2 = ""

TextBox3 = ""

Range("D3").Value = ""

Range("D4").Value = ""

Range("D5").Value = ""

TextBox1.SetFocus

End Sub

Private Sub CmdSalir_Click()

End

End Sub
Mantenimiento y Busqueda

Private Sub CommandButton1_Click()


On Error GoTonoencontro
Cells.Find(What:=TextBox1, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False).Activate
ActiveCell.Offset(0, 1).Select
TextBox2 = ActiveCell
ActiveCell.Offset(0, 1).Select
TextBox3 = ActiveCell
noencontro:
End Sub
Private Sub CommandButton2_Click()
Selection.EntireRow.Delete
Range("A9").Select
TextBox1 = Empty
TextBox2 = Empty
TextBox3 = Empty
TextBox1.SetFocus
End Sub

Private Sub CommandButton3_Click()


Range("A9").Select
Selection.EntireRow.Insert
TextBox1 = Empty
TextBox2 = Empty
TextBox3 = Empty
TextBox1.SetFocus
End Sub

Private Sub TextBox1_Change()


Range("A9").FormulaR1C1 = TextBox1
End Sub

Private Sub TextBox2_Change()


Range("B9").FormulaR1C1 = TextBox2
End Sub
Private Sub TextBox3_Change()
Range("C9").FormulaR1C1 = TextBox3
End Sub

Вам также может понравиться