4 ANALYSIS OF THE CASE DATA
A: VTT Managers
4.2.2 Planned and realised process nets
Elaborado por: Daniel Zegarra Zavaleta Pag. 118 5. En la hoja Equipo ingrese lo siguiente:
6. En la hoja Materiales ingrese lo siguiente:
7. Ingresar a Visual Basic y en una hoja de módulo escriba el siguiente código para las macros:
Sub CreaCodigo()
If Range("B3") = "" Then Exit Sub Cuadro = Range("B3")
Sheets(Cuadro).Select Range("A3").Select
Selection.Sort Key1:=Range("A3"), Order1:=xlAscending, Header:= _ xlGuess, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, DataOption1:=xlSortNormal Selection.End(xlDown).Select
Cod = Left(ActiveCell, 1) & Right("000" & _ Val(Right(ActiveCell, 4)) + 1, 4) Sheets("Datos").Select Range("B4") = Cod End Sub Sub Registrar() Cuadro = Range("B3") Codigo = Range("B4") Descripcion = Range("B5") Unidad = Range("B6") Costo = Range("B7") Sheets(Cuadro).Select Range("A3").Select
While ActiveCell <> Empty
Elaborado por: Daniel Zegarra Zavaleta Pag. 119 Wend ActiveCell = Codigo ActiveCell.Offset(0, 1) = Descripcion ActiveCell.Offset(0, 2) = Unidad ActiveCell.Offset(0, 3) = Costo Sheets("Datos").Select
MsgBox ("Los datos han sido registrados exitosamente") Range("B3:B7").ClearContents
End Sub
8. Regrese a Excel y asigne las macros “CreaCodigo” y “Registrar” a los botones correspondientes.
9. Finalmente guarde el libro con el nombre “Registrar Datos en Listas” en un archivo habilitado para macros.
Elaborado por: Daniel Zegarra Zavaleta Pag. 120
Práctica De Laboratorio Nº3
Objetivos:
Utilizar las distintas sentencias de control para la solución de múltiples tareas en el manejo de datos. Las sentencias de control a utilizarse son las siguientes:
If..then..else,
Select Case
While…wend,
For…next,
For each…next.
1. En la hoja de cálculo escribir los siguientes datos:
2. En Visual Basic insertar una hoja de módulo y escribir las siguientes subrutinas:
'POSICIONA EL PUNTERO DEBAJO DEL TITULO EDAD Sub PrimeraEdad1() Range("A3").Select ActiveCell.CurrentRegion.Columns(4).Select ActiveCell.Offset(1, 0).Select End Sub Sub PrimeraEdad2() Range("A3").Select
Elaborado por: Daniel Zegarra Zavaleta Pag. 121
ActiveCell.CurrentRegion.Select ActiveCell.Select
While ActiveCell <> "Edad"
ActiveCell.Offset(0, 1).Select Wend
ActiveCell.Offset(1, 0).Select End Sub
'POSICIONA EL PUNTERO EN LA PRIMERA COLUMNA AL FINAL DE LA LISTA Sub Nuevo() Range("A3").End(xlDown).Offset(1, 0).Select End Sub Sub Nuevo2() Range("A3").Select ActiveCell.CurrentRegion.Select ActiveCell.Offset(Selection.Rows.Count,0).Select End Sub Sub Nuevo3() Range("A3").Select
While ActiveCell <> Empty
ActiveCell.Offset(1, 0).Select Wend
End Sub
'CUENTA LA CANTIDAD DE ALUMNOS INSCRITOS Sub ContarInscritos()
Range("A4").Select N = 0
While ActiveCell <> Empty N = N + 1
ActiveCell.Offset(1, 0).Select Wend
MsgBox ("Hay " & N & " alumnos inscritos") End Sub
'CUENTA LA CANTIDAD DE MUJERES Y HOMBRES INSCRITOS Sub ContarPorSexo1()
Range("A4").Select H = 0
M = 0
While ActiveCell <> Empty
If ActiveCell.Offset(0, 2) = "M" Then H = H + 1 If ActiveCell.Offset(0, 2) = "F" Then M = M + 1 ActiveCell.Offset(1, 0).Select
Wend
MsgBox ("Hay " & M & " Mujeres y " & H & " Hombres inscritos") End Sub
Sub ContarPorSexo2() Range("A3").Select
Elaborado por: Daniel Zegarra Zavaleta Pag. 122
ActiveCell.CurrentRegion.Columns(3).Select
H = Application.WorksheetFunction.CountIf(Selection, "M") M = Application.WorksheetFunction.CountIf(Selection, "F") Range("A3").Select
MsgBox ("Hay " & M & " Mujeres y " & H & " Hombres inscritos") End Sub
'INDICA EL TIPO DE PERSONA SEGUN SU EDAD Sub TipoPersona()
Edad = Val(InputBox("Ingrese su edad")) If Edad = Empty Then Exit Sub
If Edad < 18 Then MsgBox ("Ud. es menor de Edad") If Edad >= 18 Then MsgBox ("Ud. es mayor de edad") End Sub
'INSCRIBE A UNA PERSONA AL FINAL DE LA LISTA Sub Inscripcion()
Nombre = InputBox("Ingrese el Nombre de la persona:") Range("A3").End(xlDown).Offset(1, 0).Select
ActiveCell = Nombre End Sub
'REGISTRA LA ENTREGA DE CARNET A LOS ALUMNOS Sub Entrega1()
Range("A3").Select
Nombre = InputBox("Ingrese el Nombre de la persona:") If Nombre = Empty Then Exit Sub
While ActiveCell <> Empty
ActiveCell.Offset(1, 0).Select
If UCase(ActiveCell) = UCase(Nombre) Then
If ActiveCell.Offset(0, 1) = "Entregado" Then
MsgBox ("A " & Nombre & " ya se le ha entregado su Carnet") Exit Sub End If ActiveCell.Offset(0, 1) = "Entregado" Exit Sub End If Wend
MsgBox (Nombre & " no existe en esta lista") End Sub
Sub Entrega2()
Range("A3").Select
Nombre = InputBox("Ingrese el Nombre de la persona:") If Nombre = "" Then Exit Sub
While ActiveCell <> Nombre
ActiveCell.Offset(1, 0).Select If ActiveCell = Empty Then
MsgBox (Nombre & " no existe en esta lista") Exit Sub
End If Wend
Elaborado por: Daniel Zegarra Zavaleta Pag. 123
ActiveCell.Offset(0, 1) = "Entregado" End Sub
'IDENTIFICA EL TIPO DE PERSONA PARA CADA ALUMNO Sub Persona()
Range("A4").Select
While ActiveCell <> Empty
Edad = ActiveCell.Offset(0, 3)
Select Case Edad Case Is >= 18 ActiveCell.Offset(0, 4) = "Adulto" Case 13 To 17 ActiveCell.Offset(0, 4) = "Adolescente" Case 1 To 13 If ActiveCell.Offset(0, 2) = "M" Then ActiveCell.Offset(0, 4) = "Niño" Else ActiveCell.Offset(0, 4) = "Niña" End If End Select ActiveCell.Offset(1, 0).Select Wend End Sub
'CALCULA LA DEUDA DE CADA ALUMNO Sub CalculaDeuda() Range("A3").CurrentRegion.Select Alumnos = Selection.Rows.Count - 1 Range("G4").Select For N = 1 To Alumnos ActiveCell = 200 - ActiveCell.Offset(0, -1) ActiveCell.Offset(1, 0).Select Next End Sub
'CUENTA LA CANTIDAD DE MUJERES Y HOMBRES INSCRITOS Sub ContarPorSexo3() Range("A3").CurrentRegion.Select Alumnos = Selection.Rows.Count - 1 Range("C4").Select H = 0 M = 0 For N = 1 To Alumnos If ActiveCell = "M" Then H = H + 1 If ActiveCell = "F" Then M = M + 1 ActiveCell.Offset(1, 0).Select Next
MsgBox ("Hay " & M & " Mujeres y " & H & " Hombres inscritos") End Sub
Sub ContarPorSexo4()
Range("A3").CurrentRegion.Columns("C").Select H = 0
Elaborado por: Daniel Zegarra Zavaleta Pag. 124
M = 0
For Each Celda In Selection
If Celda = "M" Then H = H + 1 If Celda = "F" Then M = M + 1 Next
MsgBox ("Hay " & M & " Mujeres y " & H & " Hombres inscritos") End Sub
'BORRA LOS PAGOS QUE SON CERO Sub BorraCeros()
Range("A3").CurrentRegion.Columns("F:G").Select N = 0
For Each Celda In Selection
If Celda = 0 Then Celda.ClearContents: N = N + 1 Next
MsgBox "habian " & N & " ceros" End Sub
'OCULTA TODAS LAS HOJAS MENOS LA ACTIVA Sub OcultarHojas()
N = 1
For Each H In Worksheets
If ActiveSheet.Name <> H.Name Then H.Visible = False N = N + 1
Next End Sub
'MUESTRA TODAS LAS HOJAS Sub MostrarHojas()
N = 1
For Each H In Worksheets
If ActiveSheet.Name <> H.Name Then H.Visible = True N = N + 1
Next End Sub
'CREA 2 HOJAS MUJERES Y HOMBRES Y COPIA A LOS ALUMNOS EN ELLAS Sub SeparaAlumnos()
Application.DisplayAlerts = False For Each H In Worksheets
If H.Name = "Hombres" Then Sheets("Hombres").Delete Next
For Each H In Worksheets
If H.Name = "Mujeres" Then Sheets("Mujeres").Delete Next
Range("A3").Select
Selection.AutoFilter Field:=3, Criteria1:="M" Selection.CurrentRegion.Select
Selection.Copy Sheets.Add
ActiveSheet.Name = "Hombres" Range("A3").Select
Elaborado por: Daniel Zegarra Zavaleta Pag. 125 ActiveSheet.Paste Application.CutCopyMode = False ActiveCell.Select Sheets("Hoja1").Select Range("A3").Select
Selection.AutoFilter Field:=3, Criteria1:="F" Selection.CurrentRegion.Select Selection.Copy Sheets.Add ActiveSheet.Name = "Mujeres" Range("A3").Select ActiveSheet.Paste Application.CutCopyMode = False ActiveCell.Select Sheets("Hoja1").Select Range("A3").Select Selection.AutoFilter End Sub
Elaborado por: Daniel Zegarra Zavaleta Pag. 126
Práctica De Laboratorio Nº4
Objetivos:
Se desea ingresar datos de diferentes clientes en una lista, utilizando tres métodos diferentes:.
Copiando datos del cliente desde un rango de celdas.
Ingresar datos del cliente utilizando ventanas de Inputbox.
Ingresar datos del cliente a través de formularios
3. En la hoja de cálculo escribir los siguientes datos:
4. Luego dibuje tres botones rectangulares tal como se aprecia en la figura.
5. A continuación ingrese a Visual Basic, inserte una hoja de módulo y en ella escriba las siguientes subrutinas:
Sub IngresoDatos1()
Rpta = MsgBox("¿Seguro desea registrar estos datos?", vbYesNo) If Rpta = vbNo Then Exit Sub
Elaborado por: Daniel Zegarra Zavaleta Pag. 127
Cliente = Range("B7") Telefono = Range("B8") Range("A11").Select
While ActiveCell <> Empty If ActiveCell = DNI Then
Rpta = MsgBox("Cliente ya existe, desea reemplazarlo?", vbYesNo) If Rpta = vbYes Then GoTo Sigue
Exit Sub End If ActiveCell.Offset(1, 0).Select Wend Sigue: ActiveCell = DNI ActiveCell.NumberFormat = "00000000" ActiveCell.Offset(0, 1) = Cliente ActiveCell.Offset(0, 2) = Telefono ActiveCell.Offset(0, 2).NumberFormat = "#-####" Range("B6:B8").ClearContents Range("B6").Select End Sub Sub IngresoDatos2()
DNI = Val(InputBox("Ingrese DNI"))
Cliente = InputBox("Ingrese nombre del cliente")
Telefono = Val(InputBox("Ingrese numero de telefono")) Range("A11").Select
While ActiveCell <> Empty If ActiveCell = DNI Then
Rpta = MsgBox("Cliente ya existe, desea reemplazarlo?", vbYesNo) If Rpta = vbYes Then GoTo Sigue
Exit Sub End If ActiveCell.Offset(1, 0).Select Wend Sigue: ActiveCell = DNI ActiveCell.NumberFormat = "00000000" ActiveCell.Offset(0, 1) = Cliente ActiveCell.Offset(0, 2) = Telefono ActiveCell.Offset(0, 2).NumberFormat = "#-####" End Sub Sub IngresoDatos3() Ficha1.Show End Sub
6. Luego inserte una hoja de formulario (menú Insertar/Userform) y diseñe en ella el formulario tal como se muestra a continuación:
Elaborado por: Daniel Zegarra Zavaleta Pag. 128 7. Seleccione el fondo del formulario, y en la ventana Propiedades póngale en la propiedad
(Name) el nombre Ficha1
8. También póngale nombre a cada cuadro de texto: DNI, Cliente y Telefono, respectivamente .
9. Igualmente con la propiedad (Name), póngale nombres a los botones de comando: Registrar, y Cancelar, respectivamente.
10. Luego haga doble clic en el botón Registrar, y escriba el siguiente código:
Private Sub Registrar_Click() Range("A11").Select
While ActiveCell <> Empty
If ActiveCell = Val(DNI) Then
Rpta = MsgBox("Cliente ya existe, desea reemplazarlo?", vbYesNo) If Rpta = vbYes Then GoTo Sigue
Elaborado por: Daniel Zegarra Zavaleta Pag. 129 End If ActiveCell.Offset(1, 0).Select Wend Sigue: ActiveCell = Val(DNI) ActiveCell.NumberFormat = "00000000" ActiveCell.Offset(0, 1) = Cliente ActiveCell.Offset(0, 2) = Val(Telefono) ActiveCell.Offset(0, 2).NumberFormat = "#-####" DNI = "" Cliente = "" Telefono = "" DNI.SetFocus End Sub
11. Seguidamente regrese al formulario y haga doble clic en el botón de comando Cancelar, y allí escriba el siguiente código:
Private Sub Cancelar_Click() Unload Me
End Sub
12. Regrese a la ventana de Excel, y asigne a cada uno de los botones las macros: “IngresoDatos1”,”IngresoDatos2”, e “IngresoDatos3” respectivamente.
13. Finalmente guarde el libro con el nombre “Ingreso de Clientes” en un archivo habilitado para macros.
Elaborado por: Daniel Zegarra Zavaleta Pag. 130
Práctica De Laboratorio Nº5
Objetivos:
Se van a confeccionar un cuadro que permita controlar las horas de ingreso y salida del personal de vigilancia de la empresa, para luego al final de la semana calcular el monto del pago por este servicio.
Uso de elementos de formulario.
Manejo de Fechas y Horas y sus respectivos formatos
Empleo de las funciones Now y CountA en Visual Basic
Protección de la hoja de calculo con contraseñas
Como crear macros que asignan otras macros.
Un Empresa contrata los servicios de un vigilante particular el cual debe cumplir con un horario normal de 8:00 de mañana hasta las 4:00 de la tarde, y por lo cual se le pagará un jornal diario de 90 soles.
Adicionalmente se han acordado estas otras condiciones que deberán cumplirse por ambas partes:
Si trabaja 5 días a la semana sin faltar, hay una bonificación de 1 jornal adicional.
Por cada minuto de tardanza habrá un descuento de 1 sol.
Por tiempo extra de trabajo previamente autorizado, se pagará el doble que las horas normales.