Option Explicit Sub looPaevik() Dim algleht As Worksheet, aineleht As Worksheet Dim paevik As Workbook Dim ainenr As Integer, opnr As Integer, nadalanr As Integer Dim algaeg As Date Set algleht = Sheet1 Set paevik = Workbooks.Add algaeg = DateSerial(2005, 9, 4) ainenr = 1 While Len(algleht.Cells(ainenr, 2)) > 0 Set aineleht = paevik.Sheets.Add aineleht.Name = algleht.Cells(ainenr, 2) opnr = 2 While Len(algleht.Cells(opnr, 1)) > 0 aineleht.Cells(opnr, 1) = algleht.Cells(opnr, 1) opnr = opnr + 1 Wend For nadalanr = 1 To 16 aineleht.Cells(1, nadalanr + 1) = algaeg + _ (nadalanr - 1) * 7 + algleht.Cells(ainenr, 4) Next nadalanr ainenr = ainenr + 1 'Debug.Print ainenr 'Debug.Assert ainenr < 100 'assert peatub, kui tingimus on vigane Wend Application.DisplayAlerts = False paevik.Sheets("sheet1").Delete paevik.Sheets("sheet2").Delete paevik.Sheets("sheet3").Delete Application.DisplayAlerts = True paevik.SaveAs "paevik.xls" End Sub Sub paevaKatse() Workbooks("klassiandmed.xls").Worksheets("sheet1"). _ Range("f3") = Date + 1 Workbooks("klassiandmed.xls").Worksheets("sheet1"). _ Range("f4") = DateSerial(2005, 9, 5) + 7 End Sub '=INT(RAND()*4+2) Sub jukuHinded() Dim raamat As Workbook Dim uusraamat As Workbook Dim opilaseleht As Worksheet 'Dim aineleht As Worksheet Dim ainenr As Integer Dim opilasenr As Integer Set raamat = Workbooks("paevik.xls") Set uusraamat = Workbooks.Add Set opilaseleht = uusraamat.Worksheets.Add opilasenr = 4 opilaseleht.Name = raamat.Sheets(1).Cells(opilasenr, 1) For ainenr = 1 To raamat.Sheets.Count opilaseleht.Cells(ainenr, 1) = raamat.Sheets(ainenr).Name opilaseleht.Cells(ainenr, 2) = _ raamat.Sheets(ainenr).Cells(opilasenr, 2) Next ainenr End Sub 'Loo igale õpilasele tema esimese hinde leht Sub kõigiEsimeneHinne() Dim raamat As Workbook Dim uusraamat As Workbook Dim opilaseleht As Worksheet 'Dim aineleht As Worksheet Dim ainenr As Integer Dim opilasenr As Integer Set raamat = Workbooks("paevik.xls") Set uusraamat = Workbooks.Add For opilasenr = 2 To 14 Set opilaseleht = uusraamat.Worksheets.Add opilaseleht.Name = raamat.Sheets(1).Cells(opilasenr, 1) For ainenr = 1 To raamat.Sheets.Count opilaseleht.Cells(ainenr, 1) = raamat.Sheets(ainenr).Name opilaseleht.Cells(ainenr, 2) = _ raamat.Sheets(ainenr).Cells(opilasenr, 2) Next ainenr Next opilasenr End Sub 'Kogu kokku lehele õpilase kõik hinded Sub kõigiKõikHinded() Dim raamat As Workbook Dim uusraamat As Workbook Dim opilaseleht As Worksheet 'Dim aineleht As Worksheet Dim ainenr As Integer, uuehindeveerg As Integer, hindeveerg As Integer Dim opilasenr As Integer Set raamat = Workbooks("paevik.xls") Set uusraamat = Workbooks.Add For opilasenr = 2 To 14 Set opilaseleht = uusraamat.Worksheets.Add opilaseleht.Name = raamat.Sheets(1).Cells(opilasenr, 1) For ainenr = 1 To raamat.Sheets.Count opilaseleht.Cells(ainenr, 1) = raamat.Sheets(ainenr).Name uuehindeveerg = 2 For hindeveerg = 2 To 17 If Len(raamat.Sheets(ainenr).Cells(opilasenr, hindeveerg)) > 0 Then opilaseleht.Cells(ainenr, uuehindeveerg) = _ raamat.Sheets(ainenr).Cells(opilasenr, hindeveerg) uuehindeveerg = uuehindeveerg + 1 End If Next hindeveerg Next ainenr Next opilasenr End Sub