Anda di halaman 1dari 12

ALGUNOS EJEMPLOS DE MACROS QUE SE REALIZÓ CON

LOS ALUMNOS - 2018


Ejercicio 1. Realice una macro simple que halle las 4 operaciones matemáticas al
ingresar dos números mediante caja de ingreso

Sub SUMA()
Range("H3").Value = InputBox("INGRESE PRIMER NUMERO", "INGRESO DE DATOS")
Range("H5").Value = InputBox("INGRESE SEGUNDO NUMERO", "INGRESO DE DATOS")
Range("H7").Value = Range("H3").Value + Range("H5").Value
End Sub

Sub RESTA()
Range("H3").Value = InputBox("INGRESE PRIMER NUMERO", "INGRESO DE DATOS")
Range("H5").Value = InputBox("INGRESE SEGUNDO NUMERO", "INGRESO DE DATOS")
Range("H7").Value = Range("H3").Value - Range("H5").Value
End Sub

Sub MULTIPLICACIÓN()
Range("H3").Value = InputBox("INGRESE PRIMER NUMERO", "INGRESO DE DATOS")
Range("H5").Value = InputBox("INGRESE SEGUNDO NUMERO", "INGRESO DE DATOS")
Range("H7").Value = Range("H3").Value * Range("H5").Value
End Sub

Sub DIVISIÓN()
Range("H3").Value = InputBox("INGRESE PRIMER NUMERO", "INGRESO DE DATOS")
Range("H5").Value = InputBox("INGRESE SEGUNDO NUMERO", "INGRESO DE DATOS")
Range("H7").Value = Range("H3").Value / Range("H5").Value
End Sub

Sub LIMPIAR()
Range("H3").ClearContents
Range("H5").ClearContents
Range("H7").ClearContents
End Sub
Ejercicio 2. Realice una macro que halle el área de las figuras geométricas básicas

Sub CUADRADO()
Range("D5").Value = InputBox("INGRESE PRIMER LADO", "ÁREA DEL CUADRADO")
Range("D7").Value = Range("D5").Value ^ 2
End Sub
Sub LIMPIARCADRADO()
Range("D5").ClearContents
Range("D7").ClearContents
End Sub

Sub TRIÁNGULO()
Range("J5").Value = InputBox("INGRESE BASE", "ÁREA DEL TRIÁNGULO")
Range("J7").Value = InputBox("INGRESE ALTURA", "ÁREA DEL TRIÁNGULO")
Range("J9").Value = Range("J5").Value * Range("J7").Value / 2
End Sub
Sub LIMPIARTRIÁNGULO()
Range("J5").ClearContents
Range("J7").ClearContents
Range("J9").ClearContents
End Sub

Sub RECTÁNGULO()
Range("D14").Value = InputBox("INGRESE BASE", "ÁREA DEL RECTÁNGULO")
Range("D16").Value = InputBox("INGRESE ALTURA", "ÁREA DEL RECTÁNGULO")
Range("D18").Value = Range("D14").Value * Range("D16").Value
End Sub
Sub LIMPIARRECTÁNGULO()
Range("D14").ClearContents
Range("D16").ClearContents
Range("D18").ClearContents
End Sub

Sub CÍRCULO()
Range("J16").Value = InputBox("INGRESE RADIO", "ÁREA DEL CÍRCULO")
Range("J18").Value = Range("J14").Value * Range("J16").Value
End Sub
Sub LIMPIARCÍRCULO()
Range("J16").ClearContents
Range("J18").ClearContents
End Sub
Ejercicio 3. Realice una macro que halle la suma de dos números. Si se ingresa
mediante caja de ingreso, esta macro deberá hablar el ingreso de
números y el resultado.

Sub HABLADOR()
Range("D1").Speak
Range("F3").Value = InputBox("INGRESE PRIMER NUMERO", "INGRESO DE DATO")
Range("D3").Speak
Range("F3").Speak

Range("F5").Value = InputBox("INGRESE SEGUNDO NUMERO", "INGRESO DE DATO")


Range("D5").Speak
Range("F5").Speak

Range("F7").Value = Range("F3").Value + Range("F5").Value


Range("D7").Speak
Range("F7").Speak
End Sub
Sub BORRADOR()
Range("F3").ClearContents
Range("F5").ClearContents
Range("F7").ClearContents
Range("H6").Speak
End Sub

Ejercicio 4. Se desea saber la condición de edad de una persona


Sub EDAD()
Dim NOMBRE As String
Dim EDAD As Integer

Range("A3").Speak
NOMBRE = InputBox("INGRESE EL NOMBRE DE LA PERSONA", "INGRESO DE DATOS")
Range("B3").Value = NOMBRE
Range("B3").Speak
Range("B2").Speak

Range("A5").Speak
Range("C2").Speak
Range("B3").Speak
EDAD = InputBox("INGRESE EDAD", "INGRESO DE DATOS")
Range("B5").Value = EDAD
Range("B5").Speak
Range("C4").Speak
Range("B2").Speak

If Range("B5").Value >= 18 Then


Range("B7").Value = ("MAYOR DE EDAD")
Range("B3").Speak
Range("C3").Speak
Range("B5").Speak
Range("C4").Speak
Range("C5").Speak
Range("B7").Speak
Else
Range("B7").Value = ("MANOR DE EDAD")
Range("B3").Speak
Range("C3").Speak
Range("B5").Speak
Range("C4").Speak
Range("C5").Speak
Range("B7").Speak
End If

End Sub
Sub LIMPIAR()
Range("B3").ClearContents
Range("B5").ClearContents
Range("B7").ClearContents
End Sub

Ejercicio 5. El jardín de niños “Mis Pasitos” cuenta con dos secciones (abejitas y
conejitos) y desea una macro que permita generar la lista de las 02
secciones con los siguientes campos: CÓDIGO, NOMBRES, APELLIDO
PATERNO, APELLIDO MATERNO, SEXO, DNI, EDAD Y DIRECCIÓN
Sub DIRIGIR()
Sheets("DATOS").Select

MsgBox ("BIENVENIDO A LA VENTADA DE MATRÍCULAS")


End Sub
Sub RELLENAR()
Dim COD, NOM, APATER, AMATER, SEXO, DNI, DIREC, SECC As String
Dim EDAD As Integer

COD = InputBox("INGRESE CÓDIGO", "INGRESO DE DATOS")


Range("D3").Value = COD

NOM = InputBox("INGRESE NOMBRES", "INGRESO DE DATOS")


Range("D5").Value = NOM

APATER = InputBox("INGRESE APELLIDO PATERNO", "INGRESO DE DATOS")


Range("D7").Value = APATER

AMATER = InputBox("INGRESE APELLIDO MATERNO", "INGRESO DE DATOS")


Range("D9").Value = AMATER

SEXO = InputBox("INGRESE SEXO", "INGRESO DE DATOS")


Range("D11").Value = SEXO

DNI = InputBox("INGRESE NÚMERO DE DNI", "INGRESO DE DATOS")


Range("D13").Value = DNI

EDAD = InputBox("INGRESE CÓDIGO", "INGRESO DE DATOS")


Range("D15").Value = EDAD

DIREC = InputBox("INGRESE DIRECCIÓN", "INGRESO DE DATOS")


Range("D17").Value = DIREC

SECC = InputBox("INGRESE SECCIÓN", "INGRESO DE DATOS")


Range("D19").Value = SECC
End Sub
Sub GUARDAR()
Dim ULTIMAFILA As Integer

If Range("D19").Value = "ABEJITAS" Then

Sheets("ABEJITAS").Select
ULTIMAFILA = ActiveSheet.UsedRange.Row - 1 + ActiveSheet.UsedRange.Rows.Count

Cells(ULTIMAFILA + 1, 3) = Sheets("DATOS").Range("D3").Value
Cells(ULTIMAFILA + 1, 4) = Sheets("DATOS").Range("D5").Value
Cells(ULTIMAFILA + 1, 5) = Sheets("DATOS").Range("D7").Value
Cells(ULTIMAFILA + 1, 6) = Sheets("DATOS").Range("D9").Value
Cells(ULTIMAFILA + 1, 7) = Sheets("DATOS").Range("D11").Value
Cells(ULTIMAFILA + 1, 8) = Sheets("DATOS").Range("D13").Value
Cells(ULTIMAFILA + 1, 9) = Sheets("DATOS").Range("D15").Value
Cells(ULTIMAFILA + 1, 10) = Sheets("DATOS").Range("D17").Value

Sheets("DATOS").Select

MsgBox ("USUARIO REGISTRADO SATISFACTORIAMENTE EN LAS SECCIÓN ABEJITAS")

End If

If Range("D19").Value = "CONEJITOS" Then

Sheets("CONEJITOS").Select
ULTIMAFILA = ActiveSheet.UsedRange.Row - 1 + ActiveSheet.UsedRange.Rows.Count

Cells(ULTIMAFILA + 1, 3) = Sheets("DATOS").Range("D3").Value
Cells(ULTIMAFILA + 1, 4) = Sheets("DATOS").Range("D5").Value
Cells(ULTIMAFILA + 1, 5) = Sheets("DATOS").Range("D7").Value
Cells(ULTIMAFILA + 1, 6) = Sheets("DATOS").Range("D9").Value
Cells(ULTIMAFILA + 1, 7) = Sheets("DATOS").Range("D11").Value
Cells(ULTIMAFILA + 1, 8) = Sheets("DATOS").Range("D13").Value
Cells(ULTIMAFILA + 1, 9) = Sheets("DATOS").Range("D15").Value
Cells(ULTIMAFILA + 1, 10) = Sheets("DATOS").Range("D17").Value
Sheets("DATOS").Select

MsgBox ("USUARIO REGISTRADO SATISFACTORIAMENTE EN LAS SECCIÓN CONEJITOS")


End If

Range("D3").ClearContents
Range("D5").ClearContents
Range("D7").ClearContents
Range("D9").ClearContents
Range("D11").ClearContents
Range("D13").ClearContents
Range("D15").ClearContents
Range("D17").ClearContents
Range("D19").ClearContents
End Sub
Sub LIMPIAR()
Range("D3").ClearContents
Range("D5").ClearContents
Range("D7").ClearContents
Range("D9").ClearContents
Range("D11").ClearContents
Range("D13").ClearContents
Range("D15").ClearContents
Range("D17").ClearContents
Range("D19").ClearContents
End Sub
Sub VOLVER()
Sheets("INICIO").Select
End Sub

Ejercicio 6. Realice una macro con formulario para hallar las 4 operaciones
matemáticas
Private Sub CommandButton1_Click()
MENU.Hide
SUMA.Show
End Sub

Private Sub CommandButton2_Click()


MENU.Hide
RESTA.Show
End Sub

Private Sub CommandButton3_Click()


MENU.Hide
MULTIPLICACION.Show
End Sub

Private Sub CommandButton4_Click()


MENU.Hide
DIVISION.Show
End Sub

Private Sub CommandButton5_Click()


APPLICATION.QUIT
End Sub

Private Sub CommandButton1_Click()


TextBox3 = Val(TextBox1) + Val(TextBox2)
Range("B6").Value = TextBox1
Range("B8").Value = TextBox2
Range("B10").Value = TextBox3
End Sub

Private Sub CommandButton2_Click()


Range("B6").ClearContents
TextBox1 = ""
Range("B8").ClearContents
TextBox2 = ""
Range("B10").ClearContents
TextBox3 = ""
End Sub

Private Sub CommandButton3_Click()


SUMA.Hide
MENU.Show
End Sub

NOTA: Realizar los mismos procedimientos para hallar las otras operaciones
Ejercicio 7. Una empresa de ventas de automóviles requiere de una macro que
permita generar proforma de venta por producto (inserte imágenes un
solo combobox y un sólo listbox, etc). Dicha proforma deberá ser
impreso y deberá generar ruta automática donde se guardó el archivo.
Private Sub ComboBox1_Change()
If ComboBox1 = "TOYOTA" Then
ListBox1.RowSource = "LISTA!B2:B6"
ListBox1.Visible = True
End If

If ComboBox1 = "HYUNDAI" Then


ListBox1.RowSource = "LISTA!C2:C6"
ListBox1.Visible = True
End If

If ComboBox1 = "ISUZU" Then


ListBox1.RowSource = "LISTA!D2:D6"
ListBox1.Visible = True
End If

If ComboBox1 = "HONDA" Then


ListBox1.RowSource = "LISTA!E2:E6"
ListBox1.Visible = True
End If
End Sub

Private Sub CommandButton1_Click()


Sheets("PROFORMA").Select
TextBox3.Text = Val(TextBox1) * Val(TextBox2)
Range("A12").Value = TextBox1.Text
Range("B12").Value = ComboBox1.Text & " " & ListBox1.Text
Range("C12").Value = TextBox2.Text
Range("D12").Value = TextBox3.Text

ActiveSheet.fotografia.Picture = Image1.Picture
ActiveSheet.fotografia.PictureSizeMode = fmPictureSizeModeStretch
End Sub

Private Sub CommandButton2_Click()


'IMPRIMIR'
Sheets("PROFORMA").Select
ActiveWindow.SelectedSheets.PrintOut COPIES:=1
End Sub

Private Sub CommandButton3_Click()


TextBox1 = ""
TextBox2 = ""
TextBox3 = ""
ComboBox1 = "ELIGE UNA OPCIÓN"
ListBox1.Visible = False

Dim RutaArchivo As String


Dim RutaFoto As String

RutaArchivo = ThisWorkbook.Path
RutaFoto = RutaArchivo + "/fotos/"

If ComboBox1 = "ELIGE UNA OPCIÓN" Then


Image1.Picture = LoadPicture(RutaFoto + "LOGO.JPG")
End If
End Sub

Private Sub ListBox1_Click()


Dim RutaArchivo As String
Dim RutaFoto As String

RutaArchivo = ThisWorkbook.Path
RutaFoto = RutaArchivo + "/fotos/"

'TOYOTA'
If ListBox1 = "YARIS" Then
Image1.Picture = LoadPicture(RutaFoto + "TOYOTA YARIS.JPG")
Image1.PictureSizeMode = fmPictureSizeModeStretch
End If

If ListBox1 = "AURIS" Then


Image1.Picture = LoadPicture(RutaFoto + "TOYOTA AURIS.JPG")
Image1.PictureSizeMode = fmPictureSizeModeStretch
End If

If ListBox1 = "COROLLA" Then


Image1.Picture = LoadPicture(RutaFoto + "TOYOTA COROLLA.JPG")
Image1.PictureSizeMode = fmPictureSizeModeStretch
End If

If ListBox1 = "AVANZA" Then


Image1.Picture = LoadPicture(RutaFoto + "TOYOTA AVANZA.JPG")
Image1.PictureSizeMode = fmPictureSizeModeStretch
End If
If ListBox1 = "CAMRY" Then
Image1.Picture = LoadPicture(RutaFoto + "TOYOTA CAMRY.JPG")
Image1.PictureSizeMode = fmPictureSizeModeStretch
End If

'HYUNDAI'
If ListBox1 = "ELANTRA" Then
Image1.Picture = LoadPicture(RutaFoto + "HYUNDAI ELANTRA.JPG")
Image1.PictureSizeMode = fmPictureSizeModeStretch
End If

If ListBox1 = "VELOSTER" Then


Image1.Picture = LoadPicture(RutaFoto + "HYUNDAI VELOSTER.JPG")
Image1.PictureSizeMode = fmPictureSizeModeStretch
End If

If ListBox1 = "GRAND" Then


Image1.Picture = LoadPicture(RutaFoto + "HYUNDAI GRAND.JPG")
Image1.PictureSizeMode = fmPictureSizeModeStretch
End If

If ListBox1 = "ELITE" Then


Image1.Picture = LoadPicture(RutaFoto + "HYUNDAI ELITE.JPG")
Image1.PictureSizeMode = fmPictureSizeModeStretch
End If

If ListBox1 = "CARS" Then


Image1.Picture = LoadPicture(RutaFoto + "HYUNDAI CARS.JPG")
Image1.PictureSizeMode = fmPictureSizeModeStretch
End If

'ISUZU'
If ListBox1 = "MU-X" Then
Image1.Picture = LoadPicture(RutaFoto + "ISUZU MU-X.JPG")
Image1.PictureSizeMode = fmPictureSizeModeStretch
End If

If ListBox1 = "D-MAX" Then


Image1.Picture = LoadPicture(RutaFoto + "ISUZU D-MAX.JPG")
Image1.PictureSizeMode = fmPictureSizeModeStretch
End If

If ListBox1 = "KB" Then


Image1.Picture = LoadPicture(RutaFoto + "ISUZU KB.JPG")
Image1.PictureSizeMode = fmPictureSizeModeStretch
End If

If ListBox1 = "KAI" Then


Image1.Picture = LoadPicture(RutaFoto + "ISUZU KAI.JPG")
Image1.PictureSizeMode = fmPictureSizeModeStretch
End If
If ListBox1 = "CARS" Then
Image1.Picture = LoadPicture(RutaFoto + "ISUZU CARS.JPG")
Image1.PictureSizeMode = fmPictureSizeModeStretch
End If

'HONDA'
If ListBox1 = "ACCORD" Then
Image1.Picture = LoadPicture(RutaFoto + "HONDA ACCORD.JPG")
Image1.PictureSizeMode = fmPictureSizeModeStretch
End If

If ListBox1 = "CIVIC" Then


Image1.Picture = LoadPicture(RutaFoto + "HONDA CIVIC.JPG")
Image1.PictureSizeMode = fmPictureSizeModeStretch
End If

If ListBox1 = "CR-V" Then


Image1.Picture = LoadPicture(RutaFoto + "HONDA CR-V.JPG")
Image1.PictureSizeMode = fmPictureSizeModeStretch
End If

If ListBox1 = "HR-V" Then


Image1.Picture = LoadPicture(RutaFoto + "HONDA HR-V.JPG")
Image1.PictureSizeMode = fmPictureSizeModeStretch
End If

If ListBox1 = "WR-V" Then


Image1.Picture = LoadPicture(RutaFoto + "HONDA WR-V.JPG")
Image1.PictureSizeMode = fmPictureSizeModeStretch
End If
End Sub

Anda mungkin juga menyukai