SlideShare una empresa de Scribd logo
1 de 24
FORMULARIOS
MODULO.- MuestraFormulario
Option Explicit
'MACROS PARA MOSTRAR LOS FORMULAROS
Sub form1()
Load ALUMNOS
ALUMNOS.Show
End Sub
Sub form2()
Load Altas
Altas.Show
End Sub
Sub form3()
Load MODIFICAR
MODIFICAR.Show
End Sub
Sub form4()
Load MODIFICAR
BAJAS.Show
End Sub
MODULO.- Ordena
Sub Macro1()
Dim i As Integer
ActiveWorkbook.Worksheets("ALUMNOS").Select
Range("A365536").End(xlUp).Offset(1, 0).Select
i = ActiveCell.Row
Range("A2:J" & i).Select
ActiveWorkbook.Worksheets("ALUMNOS").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("ALUMNOS").Sort.SortFields.Add Key:=Range("A2"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("ALUMNOS").Sort
.SetRange Range("A2:J" & i)
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Hoja1.Select
Range("B9").Select
End Sub
MODULO.-Modulo2
Sub Macro2()
Dim i As Integer
ActiveWorkbook.Worksheets("EXTRAS").Select
Range("A365536").End(xlUp).Offset(1, 0).Select
i = ActiveCell.Row
Range("A2" & i).Select
ActiveWorkbook.Worksheets("EXTRAS").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("EXTRAS").Sort.SortFields.Add Key:=Range("A2"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("EXTRAS").Sort
.SetRange Range("A2" & i)
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Hoja1.Select
Range("X9").Select
End Sub
ALTAS
Option Explicit
'AGREGAR DATOS
Private Sub CommandButton1_Click()
'declaración de la variable i
Dim i As Integer
'se despliega un mensaje de advertencia si algún TextBox
'no fue llenado
'la palabra reservada "Me" hace referencia al UserForm2 (para abreviar)
'pues es lo mismo que poner UserForm2
If Me.NUMERO.Text = "" Then MsgBox ("Campo NUMERO no puede estar vacio"): _
Exit Sub
If Me.NOMBRE.Text = "" Then MsgBox ("Campo NOMBRE no puede estar vacio"): _
Exit Sub
If Me.APELLIDOP.Text = "" Then MsgBox ("Campo APELLIDO PATERNO no puede estar vacio"): _
Exit Sub
If Me.APELLIDOM.Text = "" Then MsgBox ("Campo APELLIDO MATERNO no puede estar vacio"):
_
Exit Sub
If Me.EDAD.Text = "" Then MsgBox ("Campo EDAD no puede estar vacio"): Exit Sub
If Me.LOCALIDAD.Text = "" Then MsgBox ("Campo LOCALIDAD no puede estar vacio"): _
Exit Sub
If Me.COMUNIDAD.Text = "" Then MsgBox ("Campo COMUNIDAD no puede estar vacio"): _
Exit Sub
If Me.TELEFONO.Text = "" Then MsgBox ("Campo TELEFONO no puede estar vacio"): _
Exit Sub
If Me.GRUPO.Text = "" Then MsgBox ("Campo GRUPO no puede estar vacio"): _
Exit Sub
If Me.TURNO.Text = "" Then MsgBox ("Campo TURNO no puede estar vacio"): Exit Sub
'la sentencia de abajo se pone para evitar los flashes de pantalla
Application.ScreenUpdating = False
'se selecciona la hoja 2 que es donde está el listado
Hoja2.Select
'se asigna a la variable i el valor de la última fila con datos +1
'con Range("A" & Rows.Count).End(xlUp).Row + 1, es decir,
'se va hasta la última fila de la columna "A"(1048576 en la versión 2007
'o 65536 en la versión 2003) y de allí se sube con(xlUp)hasta la primera fila
'con datos, luego se le suma una para obtener la fila donde
'se deben agregar los ítems
i = Range("A" & Rows.Count).End(xlUp).Row + 1
'se agregan los nuevos datos
Range("A" & i).Value = NUMERO.Text
Range("B" & i).Value = NOMBRE.Text
Range("C" & i).Value = APELLIDOP.Text
Range("D" & i).Value = APELLIDOM.Text
Range("E" & i).Value = EDAD.Text
Range("F" & i).Value = LOCALIDAD.Text
Range("G" & i).Value = COMUNIDAD.Text
Range("H" & i).Value = TELEFONO.Text
Range("i" & i).Value = GRUPO.Text
Range("j" & i).Value = TURNO.Text
'mensaje de advertencia
If MsgBox("¿VERIFICO QUE TODOS LOS DATOS ESTAN CORRECTOS?", vbExclamation + vbYesNo) =
_
vbYes Then
'Después de verificar que todos los datos están correctos
'se vacían los TextBox
NUMERO.Text = ""
NOMBRE.Text = ""
APELLIDOP.Text = ""
APELLIDOM.Text = ""
EDAD.Text = ""
LOCALIDAD.Text = ""
COMUNIDAD.Text = ""
TELEFONO.Text = ""
GRUPO.Text = ""
TURNO.Text = ""
'se cierra el if
End If
'se selecciona la hoja 1 para que el formulario
'aparezca en ella
Hoja1.Select
'se selecciona el rango B4 para ocultrlo detrás de un botón
Range("B4").Select
End Sub
'OCULTA EL FORMULARIO ALTAS
Private Sub CommandButton3_Click()
Application.ScreenUpdating = False
'se llama a la subrutina Macro1
'que es la que ordena alfabéticamente por marca y modelo
'me parece la mejor ubicación pues si se agregan varios vehículos
'se los ordena todos juntos y no uno por uno como seria el caso
'de habela puesto en la línea 49 de la macro CommandButton1_Click()
Macro1
'se oculta el formulario
Me.Hide 'se podría haber puesto ALTAS.Hide
'se coloca el cursor(foco) en el TextMModelo
NUMERO.SetFocus
End Sub
Private Sub UserForm_Initialize()
Dim A2 As Range
Dim B2 As Range
Dim C2 As Range
Application.ScreenUpdating = False
Hoja3.Select
Range("A2").Select
While ActiveCell <> ""
LOCALIDAD.AddItem ActiveCell
ActiveCell.Offset(1, 0).Select
Wend
Macro2
Hoja1.Select
Range("E9").Select
Hoja3.Select
Range("B2").Select
While ActiveCell <> ""
GRUPO.AddItem ActiveCell
ActiveCell.Offset(1, 0).Select
Wend
Hoja1.Select
Range("F9").Select
Hoja3.Select
Range("C2").Select
While ActiveCell <> ""
TURNO.AddItem ActiveCell
ActiveCell.Offset(1, 0).Select
Wend
Hoja1.Select
Range("G9").Select
End Sub
ALUMNOS
Option Explicit
Private Sub CommandButton1_Click()
NUMERO = ""
NOMBRE = ""
APELLIDOP = ""
APELLIDOM = ""
EDAD = ""
LOCALIDAD = ""
COMUNIDAD = ""
TELEFONO = ""
GRUPO = ""
TURNO = ""
Hoja1.Select
Range("B4").Select
ALUMNOS.Hide
End Sub
'SE MUESTRAN TODOS LOS DATOS DE LOS VEHICULOS
Private Sub NUMERO_Change()
'declaración de variables
Dim NUMEROS As String 'a esta variable se le asignará
'el modelo que se selecciona del ComboBox1
Dim idBusca As String 'busca una coincidencia con MarcaModelo
Dim fila As Integer 'variable que comienza en 1 y se incrementa
'hasta que haya coincidencia con MarcaModelo e idBusca
'se elimina el parpadeo de la pantalla
Application.ScreenUpdating = False
Sheets("ALUMNOS").Select
Range("A2").Select
fila = 1
NUMEROS = NUMERO
'se entra en un ciclo Do-While-Loop del que se sale si hay coincidencia
'entre idBusca y MarcaModelo, obteniéndose la fila de dicha coincidencia
Do While idBusca <> NUMEROS
fila = fila + 1
idBusca = Range("A" & fila).Value
Loop
NOMBRE = Range("B" & fila).Value
APELLIDOP = Range("C" & fila).Value
APELLIDOM = Range("D" & fila).Value
EDAD = Range("E" & fila).Value
LOCALIDAD = Range("F" & fila).Value
COMUNIDAD = Range("G" & fila).Value
TELEFONO = Range("H" & fila).Value
GRUPO = Range("I" & fila).Value
TURNO = Range("J" & fila).Value
'
End Sub
'ACTUALIZACION DEL ComboBox1
Private Sub NUMERO_Enter()
Dim x As Integer
Application.ScreenUpdating = False
Hoja2.Select
'Borro el contenido del combobox
Me.NUMERO.Clear
For x = 2 To Range("A" & Rows.Count).End(xlUp).Row
If Cells(x, 1) <> Empty Then NUMERO.AddItem Range("A" & x).Value
Next
Macro1
End Sub
BAJAS
Option Explicit
'BUSCA EL MODELO PARA ELIMINAR
Private Sub CommandButton1_Click()
Dim NUMEROS As String
Dim idBusca As String
Dim fila As Integer
Application.ScreenUpdating = False
Sheets("ALUMNOS").Select
fila = 1
NUMEROS = NUMERO
Do While idBusca <> NUMEROS
fila = fila + 1
idBusca = Range("A" & fila).Value
Loop
If MsgBox("¿SEGURO QUE QUIERE ELIMINAR ESTE VEHICULO?", vbExclamation + vbYesNo) = _
vbYes Then
'se selecciona la celda
Range("A" & fila).Select
'se borra toda la fila
Selection.EntireRow.Delete
End If
'se elimina el contenido del texto del ComboBox1
Me.NUMERO.Text = ""
Hoja1.Activate
End Sub
Private Sub CommandButton2_Click()
Me.Hide
End Sub
'ACTUALIZACION DEL ComboBox1
Private Sub NUMERO_Enter()
'declaramos una variable que representa las filas
'del listado que hay en la hoja 2
Dim x As Integer
Application.ScreenUpdating = False
'selección de la hoja 2
Hoja2.Select
'se limpia el ComboBox1
Me.NUMERO.Clear
'entramos en un ciclo FOR que recorre las filas de la columna A
'empezando por la fila 2 hasta la última que tiene datos
For x = 2 To Range("A" & Rows.Count).End(xlUp).Row
'tiene en cuenta si hubiera una fila vacía (no es nuestro caso)
'y luego se agrega un ítem
If Cells(x, 1) <> Empty Then NUMERO.AddItem Range("A" & x).Value
Next
Hoja1.Select
End Sub
MODIFICAR
Option Explicit
'MODIFICA DATOS
Private Sub CommandButton2_Click()
Dim NUMEROS As String
Dim idBusca As String
Dim fila As Integer
Application.ScreenUpdating = False
Sheets("ALUMNOS").Select
fila = 1
NUMEROS = NUMERO
'se busca la fila para modificar uno o varios ítems
'según el elemento del ComboBox1 que se selecciono
Do While idBusca <> NUMEROS
fila = fila + 1
idBusca = Range("A" & fila).Value
Loop
If MsgBox("¿SEGURO QUE HIZO TODOS LOS CAMBIOS AL VEHICULO?", vbExclamation + vbYesNo)
= _
vbYes Then
'se modifica algún dato de la fila hallada cuando se sale del ciclo
Range("B" & fila).Value = NOMBRE
Range("C" & fila).Value = APELLIDOP
Range("D" & fila).Value = APELLIDOM
Range("E" & fila).Value = EDAD
Range("F" & fila).Value = LOCALIDAD
Range("G" & fila).Value = COMUNIDAD
Range("H" & fila).Value = TELEFONO
Range("I" & fila).Value = GRUPO
Range("J" & fila).Value = TURNO
End If
'se vacian los ComboBox1 y TexTbox
NUMERO = ""
NOMBRE = ""
APELLIDOP = ""
APELLIDOM = ""
EDAD = ""
LOCALIDAD = ""
COMUNIDAD = ""
TELEFONO = ""
GRUPO = ""
TURNO = ""
Hoja1.Select
Range("B4").Select
End Sub
'INFORMA
Private Sub NUMERO_Change()
Dim NUMEROS As String
Dim idBusca As String
Dim fila As Integer
Application.ScreenUpdating = False
Sheets("ALUMNOS").Select
Range("A2").Select
fila = 1
NUMEROS = NUMERO
Do While idBusca <> NUMEROS
fila = fila + 1
idBusca = Range("A" & fila).Value
Loop
NOMBRE = Range("B" & fila).Value
APELLIDOP = Range("C" & fila).Value
APELLIDOM = Range("D" & fila).Value
EDAD = Range("E" & fila).Value
LOCALIDAD = Range("F" & fila).Value
COMUNIDAD = Range("G" & fila).Value
TELEFONO = Range("H" & fila).Value
GRUPO = Range("I" & fila).Value
TURNO = Range("J" & fila).Value
End Sub
Private Sub CommandButton1_Click()
Hoja1.Select
Range("B4").Select
Me.Hide
End Sub
End Sub
'CARGA Y ACTUALIZA EL COMBOBOX
Private Sub NUMERO_Enter()
Dim x As Integer
Application.ScreenUpdating = False
Hoja2.Select
Me.NUMERO.Clear
For x = 2 To Range("A" & Rows.Count).End(xlUp).Row
If Cells(x, 1) <> Empty Then NUMERO.AddItem Range("A" & x).Value
Next
End Sub
Private Sub UserForm_Initialize()
Dim A2 As Range
Dim B2 As Range
Dim C2 As Range
Application.ScreenUpdating = False
Hoja3.Select
Range("A2").Select
While ActiveCell <> ""
LOCALIDAD.AddItem ActiveCell
ActiveCell.Offset(1, 0).Select
Wend
Macro2
Hoja1.Select
Range("E9").Select
Hoja3.Select
Range("B2").Select
While ActiveCell <> ""
GRUPO.AddItem ActiveCell
ActiveCell.Offset(1, 0).Select
Wend
Hoja1.Select
Range("F9").Select
Hoja3.Select
Range("C2").Select
While ActiveCell <> ""
TURNO.AddItem ActiveCell
ActiveCell.Offset(1, 0).Select
Wend
Hoja1.Select
Range("G9").Select
End Sub
Hoja1
ALUMNOS
EXTRAS
Formularios y módulos para gestión de alumnos

Más contenido relacionado

La actualidad más candente

Sesion 5; Media y varianza en Geogebra (LEMC USACH)
Sesion 5; Media y varianza en Geogebra (LEMC USACH)Sesion 5; Media y varianza en Geogebra (LEMC USACH)
Sesion 5; Media y varianza en Geogebra (LEMC USACH)Rafael Miranda Molina
 
Formulario De Registro De Boleta De Ventay Mantenimiento De Cliente
Formulario De Registro De Boleta De Ventay Mantenimiento De ClienteFormulario De Registro De Boleta De Ventay Mantenimiento De Cliente
Formulario De Registro De Boleta De Ventay Mantenimiento De Clientejameszx
 
Graficos de Funciones en Visual Basic subido JHS
Graficos de Funciones en Visual Basic subido JHSGraficos de Funciones en Visual Basic subido JHS
Graficos de Funciones en Visual Basic subido JHSjohnny herrera
 
Tutorial de winplot
Tutorial de winplotTutorial de winplot
Tutorial de winplotblogdevon
 
Estadística y probabilidad (quinta parte)
Estadística y probabilidad (quinta parte)Estadística y probabilidad (quinta parte)
Estadística y probabilidad (quinta parte)Matemática UESFmocc
 
Enseñar funciones con advanced grapher
Enseñar funciones con advanced grapherEnseñar funciones con advanced grapher
Enseñar funciones con advanced grapherCelina Villarroel
 
Tablas y tipos de datos en microsoft sql server
Tablas y tipos de datos en microsoft sql serverTablas y tipos de datos en microsoft sql server
Tablas y tipos de datos en microsoft sql serverkevinalexandergonzales
 
Celis perez, carlos
Celis perez, carlosCelis perez, carlos
Celis perez, carlosCELISPEREZ2
 
Estadística y probabilidad (cuarta parte)
Estadística y probabilidad (cuarta parte)Estadística y probabilidad (cuarta parte)
Estadística y probabilidad (cuarta parte)Matemática UESFmocc
 
G. sheets clase3 fórmulas básicas
G. sheets clase3 fórmulas básicasG. sheets clase3 fórmulas básicas
G. sheets clase3 fórmulas básicasJamilethFlores2
 
Programacion RPG Operaciones
Programacion RPG OperacionesProgramacion RPG Operaciones
Programacion RPG OperacionesGiovanny Guillen
 
Ejercicio excel
Ejercicio excelEjercicio excel
Ejercicio excelLuz Marina
 
Geogebra - Cartulina de Proyectos
Geogebra - Cartulina de ProyectosGeogebra - Cartulina de Proyectos
Geogebra - Cartulina de ProyectosJose Perez
 
Instrucciones hoja calculo_estadistica
Instrucciones hoja calculo_estadisticaInstrucciones hoja calculo_estadistica
Instrucciones hoja calculo_estadisticaraulprofesor
 
Trabajo de computacion
Trabajo de computacionTrabajo de computacion
Trabajo de computacionluis_xD
 
Manual de prácticas java 2015
Manual de prácticas java 2015Manual de prácticas java 2015
Manual de prácticas java 2015Ulises_312
 

La actualidad más candente (19)

Sesion 5; Media y varianza en Geogebra (LEMC USACH)
Sesion 5; Media y varianza en Geogebra (LEMC USACH)Sesion 5; Media y varianza en Geogebra (LEMC USACH)
Sesion 5; Media y varianza en Geogebra (LEMC USACH)
 
Matlab
MatlabMatlab
Matlab
 
Formulario De Registro De Boleta De Ventay Mantenimiento De Cliente
Formulario De Registro De Boleta De Ventay Mantenimiento De ClienteFormulario De Registro De Boleta De Ventay Mantenimiento De Cliente
Formulario De Registro De Boleta De Ventay Mantenimiento De Cliente
 
Graficos de Funciones en Visual Basic subido JHS
Graficos de Funciones en Visual Basic subido JHSGraficos de Funciones en Visual Basic subido JHS
Graficos de Funciones en Visual Basic subido JHS
 
Taller1
Taller1Taller1
Taller1
 
Tutorial de winplot
Tutorial de winplotTutorial de winplot
Tutorial de winplot
 
Estadística y probabilidad (quinta parte)
Estadística y probabilidad (quinta parte)Estadística y probabilidad (quinta parte)
Estadística y probabilidad (quinta parte)
 
Enseñar funciones con advanced grapher
Enseñar funciones con advanced grapherEnseñar funciones con advanced grapher
Enseñar funciones con advanced grapher
 
Tablas y tipos de datos en microsoft sql server
Tablas y tipos de datos en microsoft sql serverTablas y tipos de datos en microsoft sql server
Tablas y tipos de datos en microsoft sql server
 
Celis perez, carlos
Celis perez, carlosCelis perez, carlos
Celis perez, carlos
 
Estadística y probabilidad (cuarta parte)
Estadística y probabilidad (cuarta parte)Estadística y probabilidad (cuarta parte)
Estadística y probabilidad (cuarta parte)
 
G. sheets clase3 fórmulas básicas
G. sheets clase3 fórmulas básicasG. sheets clase3 fórmulas básicas
G. sheets clase3 fórmulas básicas
 
Programacion RPG Operaciones
Programacion RPG OperacionesProgramacion RPG Operaciones
Programacion RPG Operaciones
 
Ejercicio excel
Ejercicio excelEjercicio excel
Ejercicio excel
 
Geogebra - Cartulina de Proyectos
Geogebra - Cartulina de ProyectosGeogebra - Cartulina de Proyectos
Geogebra - Cartulina de Proyectos
 
Instrucciones hoja calculo_estadistica
Instrucciones hoja calculo_estadisticaInstrucciones hoja calculo_estadistica
Instrucciones hoja calculo_estadistica
 
Taller2
Taller2Taller2
Taller2
 
Trabajo de computacion
Trabajo de computacionTrabajo de computacion
Trabajo de computacion
 
Manual de prácticas java 2015
Manual de prácticas java 2015Manual de prácticas java 2015
Manual de prácticas java 2015
 

Similar a Formularios y módulos para gestión de alumnos

Similar a Formularios y módulos para gestión de alumnos (20)

Codigo en visual basic
Codigo en visual basicCodigo en visual basic
Codigo en visual basic
 
Arreglos, Procedimientos y Funciones
Arreglos, Procedimientos y FuncionesArreglos, Procedimientos y Funciones
Arreglos, Procedimientos y Funciones
 
Macros En Ms Excel
Macros En Ms ExcelMacros En Ms Excel
Macros En Ms Excel
 
Tutorial hp user_rpl_modo _algebraicov1.2
Tutorial hp user_rpl_modo _algebraicov1.2Tutorial hp user_rpl_modo _algebraicov1.2
Tutorial hp user_rpl_modo _algebraicov1.2
 
Formulario De Registro De Boleta De Ventay Mantenimiento De Cliente
Formulario De Registro De Boleta De Ventay Mantenimiento De ClienteFormulario De Registro De Boleta De Ventay Mantenimiento De Cliente
Formulario De Registro De Boleta De Ventay Mantenimiento De Cliente
 
codigos de algunas pantallas
codigos de algunas pantallas codigos de algunas pantallas
codigos de algunas pantallas
 
Elemento n3
Elemento n3Elemento n3
Elemento n3
 
Informe exposicion informtica
Informe exposicion informticaInforme exposicion informtica
Informe exposicion informtica
 
Codigos para el modulo 1
Codigos para el modulo 1Codigos para el modulo 1
Codigos para el modulo 1
 
Manual_Mysql Query Browser
Manual_Mysql Query BrowserManual_Mysql Query Browser
Manual_Mysql Query Browser
 
Excel y visual basic
Excel y visual basicExcel y visual basic
Excel y visual basic
 
Informe exposicion informtica
Informe exposicion informticaInforme exposicion informtica
Informe exposicion informtica
 
FUNCIONES DE EXCEL
FUNCIONES DE EXCEL FUNCIONES DE EXCEL
FUNCIONES DE EXCEL
 
Informe1
Informe1Informe1
Informe1
 
Informe grupo 1
Informe grupo 1Informe grupo 1
Informe grupo 1
 
Grupo 1 FUNCIONES DE EXCEL
Grupo 1 FUNCIONES DE EXCEL Grupo 1 FUNCIONES DE EXCEL
Grupo 1 FUNCIONES DE EXCEL
 
Informe funcion contar grupo 1
Informe funcion contar  grupo 1Informe funcion contar  grupo 1
Informe funcion contar grupo 1
 
Informe exposicion informatica
Informe exposicion informaticaInforme exposicion informatica
Informe exposicion informatica
 
Informe exposicion informatica
Informe exposicion informaticaInforme exposicion informatica
Informe exposicion informatica
 
FUNCIONES DE EXCEL
FUNCIONES DE EXCELFUNCIONES DE EXCEL
FUNCIONES DE EXCEL
 

Formularios y módulos para gestión de alumnos

  • 1. FORMULARIOS MODULO.- MuestraFormulario Option Explicit 'MACROS PARA MOSTRAR LOS FORMULAROS Sub form1() Load ALUMNOS ALUMNOS.Show End Sub Sub form2() Load Altas Altas.Show End Sub Sub form3() Load MODIFICAR MODIFICAR.Show End Sub Sub form4() Load MODIFICAR BAJAS.Show End Sub MODULO.- Ordena Sub Macro1() Dim i As Integer ActiveWorkbook.Worksheets("ALUMNOS").Select Range("A365536").End(xlUp).Offset(1, 0).Select
  • 2. i = ActiveCell.Row Range("A2:J" & i).Select ActiveWorkbook.Worksheets("ALUMNOS").Sort.SortFields.Clear ActiveWorkbook.Worksheets("ALUMNOS").Sort.SortFields.Add Key:=Range("A2"), _ SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal With ActiveWorkbook.Worksheets("ALUMNOS").Sort .SetRange Range("A2:J" & i) .Header = xlNo .MatchCase = False .Orientation = xlTopToBottom .SortMethod = xlPinYin .Apply End With Hoja1.Select Range("B9").Select End Sub MODULO.-Modulo2 Sub Macro2() Dim i As Integer ActiveWorkbook.Worksheets("EXTRAS").Select Range("A365536").End(xlUp).Offset(1, 0).Select i = ActiveCell.Row Range("A2" & i).Select ActiveWorkbook.Worksheets("EXTRAS").Sort.SortFields.Clear ActiveWorkbook.Worksheets("EXTRAS").Sort.SortFields.Add Key:=Range("A2"), _
  • 3. SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal With ActiveWorkbook.Worksheets("EXTRAS").Sort .SetRange Range("A2" & i) .Header = xlNo .MatchCase = False .Orientation = xlTopToBottom .SortMethod = xlPinYin .Apply End With Hoja1.Select Range("X9").Select End Sub ALTAS
  • 4. Option Explicit 'AGREGAR DATOS Private Sub CommandButton1_Click() 'declaración de la variable i Dim i As Integer 'se despliega un mensaje de advertencia si algún TextBox 'no fue llenado
  • 5. 'la palabra reservada "Me" hace referencia al UserForm2 (para abreviar) 'pues es lo mismo que poner UserForm2 If Me.NUMERO.Text = "" Then MsgBox ("Campo NUMERO no puede estar vacio"): _ Exit Sub If Me.NOMBRE.Text = "" Then MsgBox ("Campo NOMBRE no puede estar vacio"): _ Exit Sub If Me.APELLIDOP.Text = "" Then MsgBox ("Campo APELLIDO PATERNO no puede estar vacio"): _ Exit Sub If Me.APELLIDOM.Text = "" Then MsgBox ("Campo APELLIDO MATERNO no puede estar vacio"): _ Exit Sub If Me.EDAD.Text = "" Then MsgBox ("Campo EDAD no puede estar vacio"): Exit Sub If Me.LOCALIDAD.Text = "" Then MsgBox ("Campo LOCALIDAD no puede estar vacio"): _ Exit Sub If Me.COMUNIDAD.Text = "" Then MsgBox ("Campo COMUNIDAD no puede estar vacio"): _ Exit Sub If Me.TELEFONO.Text = "" Then MsgBox ("Campo TELEFONO no puede estar vacio"): _ Exit Sub If Me.GRUPO.Text = "" Then MsgBox ("Campo GRUPO no puede estar vacio"): _ Exit Sub If Me.TURNO.Text = "" Then MsgBox ("Campo TURNO no puede estar vacio"): Exit Sub 'la sentencia de abajo se pone para evitar los flashes de pantalla Application.ScreenUpdating = False 'se selecciona la hoja 2 que es donde está el listado Hoja2.Select
  • 6. 'se asigna a la variable i el valor de la última fila con datos +1 'con Range("A" & Rows.Count).End(xlUp).Row + 1, es decir, 'se va hasta la última fila de la columna "A"(1048576 en la versión 2007 'o 65536 en la versión 2003) y de allí se sube con(xlUp)hasta la primera fila 'con datos, luego se le suma una para obtener la fila donde 'se deben agregar los ítems i = Range("A" & Rows.Count).End(xlUp).Row + 1 'se agregan los nuevos datos Range("A" & i).Value = NUMERO.Text Range("B" & i).Value = NOMBRE.Text Range("C" & i).Value = APELLIDOP.Text Range("D" & i).Value = APELLIDOM.Text Range("E" & i).Value = EDAD.Text Range("F" & i).Value = LOCALIDAD.Text Range("G" & i).Value = COMUNIDAD.Text Range("H" & i).Value = TELEFONO.Text Range("i" & i).Value = GRUPO.Text Range("j" & i).Value = TURNO.Text 'mensaje de advertencia If MsgBox("¿VERIFICO QUE TODOS LOS DATOS ESTAN CORRECTOS?", vbExclamation + vbYesNo) = _ vbYes Then
  • 7. 'Después de verificar que todos los datos están correctos 'se vacían los TextBox NUMERO.Text = "" NOMBRE.Text = "" APELLIDOP.Text = "" APELLIDOM.Text = "" EDAD.Text = "" LOCALIDAD.Text = "" COMUNIDAD.Text = "" TELEFONO.Text = "" GRUPO.Text = "" TURNO.Text = "" 'se cierra el if End If 'se selecciona la hoja 1 para que el formulario 'aparezca en ella Hoja1.Select 'se selecciona el rango B4 para ocultrlo detrás de un botón Range("B4").Select End Sub 'OCULTA EL FORMULARIO ALTAS Private Sub CommandButton3_Click()
  • 8. Application.ScreenUpdating = False 'se llama a la subrutina Macro1 'que es la que ordena alfabéticamente por marca y modelo 'me parece la mejor ubicación pues si se agregan varios vehículos 'se los ordena todos juntos y no uno por uno como seria el caso 'de habela puesto en la línea 49 de la macro CommandButton1_Click() Macro1 'se oculta el formulario Me.Hide 'se podría haber puesto ALTAS.Hide 'se coloca el cursor(foco) en el TextMModelo NUMERO.SetFocus End Sub Private Sub UserForm_Initialize() Dim A2 As Range Dim B2 As Range Dim C2 As Range Application.ScreenUpdating = False Hoja3.Select Range("A2").Select
  • 9. While ActiveCell <> "" LOCALIDAD.AddItem ActiveCell ActiveCell.Offset(1, 0).Select Wend Macro2 Hoja1.Select Range("E9").Select Hoja3.Select Range("B2").Select While ActiveCell <> "" GRUPO.AddItem ActiveCell ActiveCell.Offset(1, 0).Select Wend Hoja1.Select Range("F9").Select Hoja3.Select Range("C2").Select While ActiveCell <> "" TURNO.AddItem ActiveCell ActiveCell.Offset(1, 0).Select Wend
  • 10. Hoja1.Select Range("G9").Select End Sub ALUMNOS Option Explicit Private Sub CommandButton1_Click() NUMERO = "" NOMBRE = ""
  • 11. APELLIDOP = "" APELLIDOM = "" EDAD = "" LOCALIDAD = "" COMUNIDAD = "" TELEFONO = "" GRUPO = "" TURNO = "" Hoja1.Select Range("B4").Select ALUMNOS.Hide End Sub 'SE MUESTRAN TODOS LOS DATOS DE LOS VEHICULOS Private Sub NUMERO_Change() 'declaración de variables Dim NUMEROS As String 'a esta variable se le asignará 'el modelo que se selecciona del ComboBox1 Dim idBusca As String 'busca una coincidencia con MarcaModelo Dim fila As Integer 'variable que comienza en 1 y se incrementa 'hasta que haya coincidencia con MarcaModelo e idBusca 'se elimina el parpadeo de la pantalla Application.ScreenUpdating = False Sheets("ALUMNOS").Select
  • 12. Range("A2").Select fila = 1 NUMEROS = NUMERO 'se entra en un ciclo Do-While-Loop del que se sale si hay coincidencia 'entre idBusca y MarcaModelo, obteniéndose la fila de dicha coincidencia Do While idBusca <> NUMEROS fila = fila + 1 idBusca = Range("A" & fila).Value Loop NOMBRE = Range("B" & fila).Value APELLIDOP = Range("C" & fila).Value APELLIDOM = Range("D" & fila).Value EDAD = Range("E" & fila).Value LOCALIDAD = Range("F" & fila).Value COMUNIDAD = Range("G" & fila).Value TELEFONO = Range("H" & fila).Value GRUPO = Range("I" & fila).Value TURNO = Range("J" & fila).Value '
  • 13. End Sub 'ACTUALIZACION DEL ComboBox1 Private Sub NUMERO_Enter() Dim x As Integer Application.ScreenUpdating = False Hoja2.Select 'Borro el contenido del combobox Me.NUMERO.Clear For x = 2 To Range("A" & Rows.Count).End(xlUp).Row If Cells(x, 1) <> Empty Then NUMERO.AddItem Range("A" & x).Value Next Macro1 End Sub BAJAS Option Explicit
  • 14. 'BUSCA EL MODELO PARA ELIMINAR Private Sub CommandButton1_Click() Dim NUMEROS As String Dim idBusca As String Dim fila As Integer Application.ScreenUpdating = False Sheets("ALUMNOS").Select fila = 1 NUMEROS = NUMERO Do While idBusca <> NUMEROS fila = fila + 1 idBusca = Range("A" & fila).Value Loop If MsgBox("¿SEGURO QUE QUIERE ELIMINAR ESTE VEHICULO?", vbExclamation + vbYesNo) = _ vbYes Then 'se selecciona la celda Range("A" & fila).Select 'se borra toda la fila Selection.EntireRow.Delete End If 'se elimina el contenido del texto del ComboBox1 Me.NUMERO.Text = ""
  • 15. Hoja1.Activate End Sub Private Sub CommandButton2_Click() Me.Hide End Sub 'ACTUALIZACION DEL ComboBox1 Private Sub NUMERO_Enter() 'declaramos una variable que representa las filas 'del listado que hay en la hoja 2 Dim x As Integer Application.ScreenUpdating = False 'selección de la hoja 2 Hoja2.Select 'se limpia el ComboBox1 Me.NUMERO.Clear 'entramos en un ciclo FOR que recorre las filas de la columna A 'empezando por la fila 2 hasta la última que tiene datos For x = 2 To Range("A" & Rows.Count).End(xlUp).Row 'tiene en cuenta si hubiera una fila vacía (no es nuestro caso) 'y luego se agrega un ítem
  • 16. If Cells(x, 1) <> Empty Then NUMERO.AddItem Range("A" & x).Value Next Hoja1.Select End Sub MODIFICAR Option Explicit 'MODIFICA DATOS Private Sub CommandButton2_Click()
  • 17. Dim NUMEROS As String Dim idBusca As String Dim fila As Integer Application.ScreenUpdating = False Sheets("ALUMNOS").Select fila = 1 NUMEROS = NUMERO 'se busca la fila para modificar uno o varios ítems 'según el elemento del ComboBox1 que se selecciono Do While idBusca <> NUMEROS fila = fila + 1 idBusca = Range("A" & fila).Value Loop If MsgBox("¿SEGURO QUE HIZO TODOS LOS CAMBIOS AL VEHICULO?", vbExclamation + vbYesNo) = _ vbYes Then 'se modifica algún dato de la fila hallada cuando se sale del ciclo Range("B" & fila).Value = NOMBRE Range("C" & fila).Value = APELLIDOP Range("D" & fila).Value = APELLIDOM Range("E" & fila).Value = EDAD Range("F" & fila).Value = LOCALIDAD Range("G" & fila).Value = COMUNIDAD
  • 18. Range("H" & fila).Value = TELEFONO Range("I" & fila).Value = GRUPO Range("J" & fila).Value = TURNO End If 'se vacian los ComboBox1 y TexTbox NUMERO = "" NOMBRE = "" APELLIDOP = "" APELLIDOM = "" EDAD = "" LOCALIDAD = "" COMUNIDAD = "" TELEFONO = "" GRUPO = "" TURNO = "" Hoja1.Select Range("B4").Select End Sub 'INFORMA Private Sub NUMERO_Change()
  • 19. Dim NUMEROS As String Dim idBusca As String Dim fila As Integer Application.ScreenUpdating = False Sheets("ALUMNOS").Select Range("A2").Select fila = 1 NUMEROS = NUMERO Do While idBusca <> NUMEROS fila = fila + 1 idBusca = Range("A" & fila).Value Loop NOMBRE = Range("B" & fila).Value APELLIDOP = Range("C" & fila).Value APELLIDOM = Range("D" & fila).Value EDAD = Range("E" & fila).Value LOCALIDAD = Range("F" & fila).Value COMUNIDAD = Range("G" & fila).Value TELEFONO = Range("H" & fila).Value GRUPO = Range("I" & fila).Value
  • 20. TURNO = Range("J" & fila).Value End Sub Private Sub CommandButton1_Click() Hoja1.Select Range("B4").Select Me.Hide End Sub End Sub 'CARGA Y ACTUALIZA EL COMBOBOX Private Sub NUMERO_Enter() Dim x As Integer Application.ScreenUpdating = False Hoja2.Select Me.NUMERO.Clear For x = 2 To Range("A" & Rows.Count).End(xlUp).Row If Cells(x, 1) <> Empty Then NUMERO.AddItem Range("A" & x).Value Next
  • 21. End Sub Private Sub UserForm_Initialize() Dim A2 As Range Dim B2 As Range Dim C2 As Range Application.ScreenUpdating = False Hoja3.Select Range("A2").Select While ActiveCell <> "" LOCALIDAD.AddItem ActiveCell ActiveCell.Offset(1, 0).Select Wend Macro2 Hoja1.Select Range("E9").Select Hoja3.Select Range("B2").Select While ActiveCell <> "" GRUPO.AddItem ActiveCell ActiveCell.Offset(1, 0).Select
  • 22. Wend Hoja1.Select Range("F9").Select Hoja3.Select Range("C2").Select While ActiveCell <> "" TURNO.AddItem ActiveCell ActiveCell.Offset(1, 0).Select Wend Hoja1.Select Range("G9").Select End Sub Hoja1