macrodsdsadassdadas

Download Macrodsdsadassdadas

If you can't read please download the document

Upload: cristian-camilo-cortes-hernandez

Post on 03-Feb-2016

220 views

Category:

Documents


4 download

DESCRIPTION

dsadasdas

TRANSCRIPT

Function BuscarHoja(nombreHoja As String) As Boolean For i = 1 To Worksheets.Count If Worksheets(i).Name = nombreHoja Then BuscarHoja = True Exit Function End If Next BuscarHoja = False End FunctionSub datos_backup()'' Crea un back up de la hoja de datos y ordena los nombres de los profesores en orden alfabtico' Dim check As Boolean check = BuscarHoja("DATOS BACKUP") If check = True Then Sheets("DATOS BACKUP").Select ActiveWindow.SelectedSheets.Delete End If Sheets.Add(After:=Worksheets("DATOS")).Name = "DATOS BACKUP" Sheets("DATOS").Select Columns("A:Y").Select Selection.Copy Sheets("DATOS BACKUP").Select ActiveSheet.Paste Range("F27").Select ActiveWindow.ScrollColumn = 2 ActiveWindow.ScrollColumn = 3 ActiveWindow.ScrollColumn = 4 ActiveWindow.ScrollColumn = 5 ActiveWindow.ScrollColumn = 6 ActiveWindow.ScrollColumn = 7 ActiveWindow.ScrollColumn = 8 ActiveWindow.ScrollColumn = 9 ActiveWindow.ScrollColumn = 10 ActiveWindow.ScrollColumn = 11 ActiveWindow.ScrollColumn = 12 ActiveWindow.ScrollColumn = 13 ActiveWindow.ScrollColumn = 14 ActiveWindow.ScrollColumn = 13 ActiveWindow.ScrollColumn = 12 ActiveWindow.ScrollColumn = 11 ActiveWindow.ScrollColumn = 10 ActiveWindow.ScrollColumn = 9 ActiveWindow.ScrollColumn = 10 Columns("M:M").Select Application.CutCopyMode = False ActiveWindow.SmallScroll Down:=-12 Range("M2:M1000").Select ActiveWorkbook.Worksheets("DATOS BACKUP").Sort.SortFields.Clear ActiveWorkbook.Worksheets("DATOS BACKUP").Sort.SortFields.Add Key:=Range("M2" _ ), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal With ActiveWorkbook.Worksheets("DATOS BACKUP").Sort .SetRange Range("A2:Y395") .Header = xlNo .MatchCase = False .Orientation = xlTopToBottom .SortMethod = xlPinYin .Apply End With ActiveWindow.SmallScroll Down:=-15End SubSub hoja_horario() Dim check As Boolean check = BuscarHoja("HORARIO X PROFESOR") If check = True Then Sheets("HORARIO X PROFESOR").Select ActiveWindow.SelectedSheets.Delete End If Sheets.Add(After:=Worksheets("DATOS BACKUP")).Name = "HORARIO X PROFESOR" ActiveCell.SelectEnd SubSub esquema_horario(profesor As String)'Crea el esqueleto del horario Sheets("HORARIO X PROFESOR").Select ActiveCell.Offset(1, 1).Range("A1").Select ActiveCell.FormulaR1C1 = "LUNES" Selection.AutoFill Destination:=ActiveCell.Range("A1:G1"), Type:= _ xlFillDefault ActiveCell.Range("A1:G1").Select ActiveCell.Offset(1, -1).Range("A1").Select ActiveCell.FormulaR1C1 = "6" ActiveCell.Offset(1, 0).Range("A1").Select ActiveCell.FormulaR1C1 = "7" ActiveCell.Offset(-1, 0).Range("A1:A2").Select Selection.AutoFill Destination:=ActiveCell.Range("A1:A15"), Type:= _ xlFillDefault ActiveCell.Range("A1:A15").Select ActiveCell.Offset(-2, 1).Range("A1").Select ActiveCell.FormulaR1C1 = "PROFESOR" ActiveCell.Offset(0, 1).Range("A1:F1").Select With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlBottom .WrapText = False .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = False End With Selection.Merge ActiveCell.Offset(0, -2).Range("A1:H17").Select Selection.Borders(xlDiagonalDown).LineStyle = xlNone Selection.Borders(xlDiagonalUp).LineStyle = xlNone With Selection.Borders(xlEdgeLeft) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlEdgeTop) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlEdgeBottom) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlEdgeRight) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlInsideVertical) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlInsideHorizontal) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlThin End With ActiveCell.Range("A2:A17,B1:H2").Select ActiveCell.Offset(0, 1).Range("A1").Activate Selection.Font.Bold = True ActiveCell.Offset(-1, -1).Range("A1").Select ActiveCell.Range("A1:A2").Select Selection.Borders(xlDiagonalDown).LineStyle = xlNone Selection.Borders(xlDiagonalUp).LineStyle = xlNone Selection.Borders(xlEdgeLeft).LineStyle = xlNone Selection.Borders(xlEdgeTop).LineStyle = xlNone Selection.Borders(xlEdgeBottom).LineStyle = xlNone With Selection.Borders(xlEdgeRight) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlThin End With Selection.Borders(xlInsideVertical).LineStyle = xlNone Selection.Borders(xlInsideHorizontal).LineStyle = xlNone ActiveCell.Offset(1, 0).Range("A1").Select Selection.Borders(xlDiagonalDown).LineStyle = xlNone Selection.Borders(xlDiagonalUp).LineStyle = xlNone Selection.Borders(xlEdgeLeft).LineStyle = xlNone Selection.Borders(xlEdgeTop).LineStyle = xlNone With Selection.Borders(xlEdgeBottom) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlEdgeRight) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlThin End With Selection.Borders(xlInsideVertical).LineStyle = xlNone Selection.Borders(xlInsideHorizontal).LineStyle = xlNone ActiveCell.Offset(-1, 2).Range("A1:F1").Select ActiveCell.FormulaR1C1 = profesor ActiveCell.Offset(1, -2).Range("A1").Select End SubSub salto_pagina()'' salto_pagina Macro' ActiveCell.Offset(18, 0).Range("A1").Select ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=ActiveCellEnd SubFunction profesores() As ObjectSet profesores = New CollectionDim celda As ObjectDim i As Integer Sheets("DATOS BACKUP").SelectFor Each celda In Range("M2:M1000") On Error Resume Next profesores.Add celda.Value, CStr(celda.Value) On Error GoTo 0Next celdaEnd FunctionSub rellenar_horario(hora_inicio As Integer, hora_final As Integer, dia As Integer, materia As String)Dim i As IntegerActiveCell.Offset(0, dia).SelectFor i = hora_inicio To hora_final - 1 If i = hora_inicio Then ActiveCell.Offset(hora_inicio - 6, 0).Select End If ActiveCell.Offset(1, 0).Select With Selection.Interior .Pattern = xlSolid .PatternColorIndex = xlAutomatic .Color = 65535 .TintAndShade = 0 .PatternTintAndShade = 0 End With ActiveCell.FormulaR1C1 = materiaNext ii = 0ActiveCell.Offset(-hora_final + 6, -dia).SelectEnd SubSub main()'datos_backuphoja_horarioDim prof As CollectionSet prof = profesores()Dim i As Integer, j As Integer, nombre As String, materia As StringDim hora_inicio As Integer, hora_final As Integer, dia As IntegerFor i = 1 To prof.Count - 1salto_paginaActiveSheet.Cells(19 * (i - 1) + 1, 1).Selectesquema_horario prof(i)nombre = prof(i) For j = 1 To 1000 If Worksheets("DATOS BACKUP").Cells(j + 1, 13).Value = nombre And Not IsEmpty(Worksheets("DATOS BACKUP").Cells(j + 1, 13)) Then hora_inicio = CDbl(Worksheets("DATOS BACKUP").Cells(j + 1, 8).Value) * 24 hora_final = CDbl(Worksheets("DATOS BACKUP").Cells(j + 1, 9).Value) * 24 dia = CDbl(Worksheets("DATOS BACKUP").Cells(j + 1, 7).Value) materia = Worksheets("DATOS BACKUP").Cells(j + 1, 2).Value rellenar_horario hora_inicio, hora_final, dia, materia End If Next jNext iEnd Sub