boxmein

vba magzcik

May 18th, 2016
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Rem Attribute VBA_ModuleType=VBAModule
  2. Option VBASupport 1
  3. '
  4. ' Ülesanne 1
  5. '
  6.  
  7. ' suvaline number a ja b vahel, a välja arvatud, b sisse arvatud
  8. ' @param a arvu alampiir
  9. ' @param b arvu ülempiir
  10. ' @returns suvaline arv a ja b vahel
  11. Function Randbetween(a As Integer, b As Integer) As Integer
  12.     ' arvutab suvalise arvu vahemikus
  13.    Randbetween = CInt((b - a + 1) * Rnd()) + a
  14. End Function
  15.  
  16. ' mängi lahutamismängu 100 piires
  17. ' 10 ringi, toimub läbi inputboxide
  18. ' mängu lõpuks saad raporti
  19. ' @returns Null
  20. Function Arvuta()
  21.     ' deklareeri muutujad
  22.    Dim i, x, y, oigeid As Integer
  23.     Dim vastus As String
  24.     ' defineeri muutujad
  25.    i = 10
  26.     oigeid = 0
  27.     ' tee 10 korda
  28.    Do
  29.         ' leia ülesande jaoks vajalikud arvud
  30.        x = Randbetween(51, 100)
  31.         y = Randbetween(1, 50)
  32.         ' küsi kasutajalt vastus
  33.        vastus = InputBox(x & " - " & y, "Leia vastus!")
  34.         If vastus = "" Then
  35.             ' cancel/tühi vastus lõpetab
  36.            GoTo tulemused
  37.         Else
  38.             ' kontrolli vastuse õigsust, anna tagasisidet
  39.            If CInt(vastus) = x - y Then
  40.                 MsgBox ("Vastus on õige!")
  41.                 ' loenda õigeid
  42.                oigeid = oigeid + 1
  43.             Else
  44.                 MsgBox ("Vastus on vale!")
  45.             End If
  46.         End If
  47.         i = i - 1
  48.     Loop While i > 0
  49.     ' deklareeri label tulemused
  50. tulemused:
  51.     ' tulemuste käigus väljasta katsete arv, õigete arv, valede arv ja hinne (hinde saame eraldi funktsioonist)
  52.    MsgBox ("Tehti " & i & " katset. Nendest " & oigeid & " õiget vastust ja " & (10 - oigeid) & " valet vastust.")
  53.     Hinda (oigeid)
  54. End Function
  55.  
  56. ' väljasta kasutajale hinne vastavalt õigete arvule
  57. ' 1..2 -> 1
  58. ' 3..4 -> 2
  59. ' ...
  60. Function Hinda(oigeid)
  61.     Dim hinne As Integer
  62.     ' leiab hinde intelligentsemal meetodil
  63.    hinne = CInt((oigeid + 1) / 2#)
  64.     MsgBox ("Hinne: " & hinne)
  65. End Function
  66.  
  67. ' (Ülesanne 2 on Module2-s)
  68.  
  69. '
  70. ' Ülesanne 3
  71. '
  72.  
  73. ' ringjoone joonistamine
  74. Function Ringjoon()
  75.     ' deklareeri muutujad
  76.    Dim raadius As Integer, pindala As Integer, ymbermoot As Integer
  77.     Dim Shp As Shape
  78.     ' defineeri muutujad kasutades aritmeetikat
  79.    ' loe andmeid töölehelt ning kirjuta töölehele
  80.    ymbermoot = CInt(Range("C1").Value)
  81.     raadius = ymbermoot / (2 * 3.14159265)
  82.     Range("C2").Value = raadius
  83.     pindala = raadius * raadius * 3.14159265
  84.     Range("C3").Value = pindala
  85.    
  86.     ' hävita varasemad ringid
  87.    For Each Shp In ActiveSheet.Shapes
  88.         ' ära hävita nuppe (button)
  89.        If Not (Shp.Type = msoFormControl) Then
  90.             Shp.Delete
  91.         End If
  92.     Next Shp
  93.     ' lisa uus ring
  94.    Set ring = ActiveSheet.Shapes.AddShape(msoShapeOval, 100, 100, raadius * 10, raadius * 10)
  95. End Function
  96.  
  97. '
  98. ' Ülesanne 4
  99. '
  100.  
  101. ' animeeri Garfield posti otsa
  102. Function Hyppa()
  103.     ' haara viide garfieldi pildile
  104.    Set pilt = ActiveSheet.Shapes("Picture 1")
  105.     ' deklareeri ja defineeri muutujad vastavalt töölehe andmetele
  106.    Dim x As Integer, y As Integer
  107.     x = Range("B1").Value
  108.     y = Range("B2").Value
  109.     ' nihuta pildi asukohta
  110.    pilt.Top = y
  111.     pilt.Left = x
  112.     ' excel 07-10 jaoks vali suvaline cell
  113.    Range("A1").Select
  114.     ' oota 3s
  115.    Application.Wait (Now() + TimeValue("00:00:03"))
  116.     ' kasuta tagasi funktsiooni
  117.    Tagasi
  118. End Function
  119.  
  120. ' aseta pilt algasendisse
  121. Function Tagasi()
  122.     ' haara viide garfieldi pildile
  123.    Set pilt = ActiveSheet.Shapes("Picture 1")
  124.     ' nihuta pilt
  125.    pilt.Top = 200
  126.     pilt.Left = 20
  127. End Function
  128.  
  129. '
  130. ' Ülesanne 5
  131. '
  132.  
  133. ' by riina
  134. Sub Hyple()
  135.     ActiveSheet.Shapes(1).IncrementTop -30
  136.     Application.Wait Now() + TimeValue("00:00:01")
  137.     ActiveSheet.Shapes(1).IncrementLeft 5
  138.     Application.Wait Now() + TimeValue("00:00:01")
  139.     ActiveSheet.Shapes(1).IncrementTop 30
  140.     Application.Wait Now() + TimeValue("00:00:01")
  141.     DoEvents
  142. End Sub
  143.  
  144. '  hüple 10x
  145. Sub HypleTsyklis()
  146.     ' dekl ja def muutujad
  147.    Dim i As Integer
  148.     i = 10
  149.     ' korda tegevust 10 korda
  150.    Do
  151.         Hyple
  152.         i = i - 1
  153.     Loop While i > 0
  154. End Sub
  155.  
  156. ' hüple kasutaja sisend arvu kordi
  157. Sub Hyple2()
  158.     ' deklar muutujad
  159.    Dim kordi_temp As String, kordi As Integer
  160.     ' kasutaja sisend
  161.    kordi_temp = InputBox("Mitu korda hüppan", "hüppenöör")
  162.     ' cancel nupu korral proovi uuesti
  163.    If kordi_temp = "" Then
  164.         MsgBox ("Palun sisesta midagi!")
  165.         ' rekursioon
  166.        Hyple2
  167.     Else
  168.         ' parse muutuja täisarvuks
  169.        kordi = CInt(kordi_temp)
  170.         ' hüple vastav arv kordi
  171.        Do
  172.             Hyple
  173.             kordi = kordi - 1
  174.         Loop While kordi > 0
  175.     End If
  176. End Sub
  177.  
  178. ' nihuta tüdruk algusesse
  179. Sub Algusesse()
  180.     ActiveSheet.Shapes(1).Left = 0
  181. End Sub
  182.  
  183.  
  184. '
  185. ' Ülesanne 6 on Module2's lindistatult & muudetult
  186. '
  187.  
  188.  
  189.  
  190. Rem Attribute VBA_ModuleType=VBAModule
  191. Option VBASupport 1
  192. ' ülesanne 2 makro
  193. ' teeb selle töötabeli vms ära
  194. Sub eyyyyy()
  195.     Range("D2").Select
  196.     ActiveCell.FormulaR1C1 = "esmaspäev"
  197.     Range("E2").Select
  198.     ActiveCell.FormulaR1C1 = "teisipäev"
  199.     Range("F2").Select
  200.     ActiveCell.FormulaR1C1 = "kolmapäev"
  201.     Range("G2").Select
  202.     ActiveCell.FormulaR1C1 = "neljapäev"
  203.     Range("H2").Select
  204.     ActiveCell.FormulaR1C1 = "reede"
  205.     Range("I2").Select
  206.     ActiveCell.FormulaR1C1 = "laupäev"
  207.     Range("C3").Select
  208.     ActiveCell.FormulaR1C1 = "8:00"
  209.     Range("C4").Select
  210.     ActiveCell.FormulaR1C1 = "9:00"
  211.     Range("C3:C4").Select
  212.     Selection.AutoFill Destination:=Range("C3:C14"), Type:=xlFillDefault
  213.     Range("C3:C14").Select
  214.     Range("D3:D8").Select
  215.     With Selection
  216.         .HorizontalAlignment = xlCenter
  217.         .VerticalAlignment = xlBottom
  218.         .WrapText = False
  219.         .Orientation = 0
  220.         .AddIndent = False
  221.         .IndentLevel = 0
  222.         .ShrinkToFit = False
  223.         .ReadingOrder = xlContext
  224.         .MergeCells = False
  225.     End With
  226.     Selection.Merge
  227.     Range("E3:E8").Select
  228.     With Selection
  229.         .HorizontalAlignment = xlCenter
  230.         .VerticalAlignment = xlBottom
  231.         .WrapText = False
  232.         .Orientation = 0
  233.         .AddIndent = False
  234.         .IndentLevel = 0
  235.         .ShrinkToFit = False
  236.         .ReadingOrder = xlContext
  237.         .MergeCells = False
  238.     End With
  239.     Selection.Merge
  240.     Range("F3:F8").Select
  241.     With Selection
  242.         .HorizontalAlignment = xlCenter
  243.         .VerticalAlignment = xlBottom
  244.         .WrapText = False
  245.         .Orientation = 0
  246.         .AddIndent = False
  247.         .IndentLevel = 0
  248.         .ShrinkToFit = False
  249.         .ReadingOrder = xlContext
  250.         .MergeCells = False
  251.     End With
  252.     Selection.Merge
  253.     Range("G3:G8").Select
  254.     With Selection
  255.         .HorizontalAlignment = xlCenter
  256.         .VerticalAlignment = xlBottom
  257.         .WrapText = False
  258.         .Orientation = 0
  259.         .AddIndent = False
  260.         .IndentLevel = 0
  261.         .ShrinkToFit = False
  262.         .ReadingOrder = xlContext
  263.         .MergeCells = False
  264.     End With
  265.     Selection.Merge
  266.     With Selection
  267.         .HorizontalAlignment = xlGeneral
  268.         .VerticalAlignment = xlBottom
  269.         .WrapText = False
  270.         .Orientation = 0
  271.         .AddIndent = False
  272.         .IndentLevel = 0
  273.         .ShrinkToFit = False
  274.         .ReadingOrder = xlContext
  275.         .MergeCells = True
  276.     End With
  277.     Selection.UnMerge
  278.     Range("H3:H8").Select
  279.     With Selection
  280.         .HorizontalAlignment = xlCenter
  281.         .VerticalAlignment = xlBottom
  282.         .WrapText = False
  283.         .Orientation = 0
  284.         .AddIndent = False
  285.         .IndentLevel = 0
  286.         .ShrinkToFit = False
  287.         .ReadingOrder = xlContext
  288.         .MergeCells = False
  289.     End With
  290.     Selection.Merge
  291.     Range("G3:G8").Select
  292.     With Selection
  293.         .HorizontalAlignment = xlCenter
  294.         .VerticalAlignment = xlBottom
  295.         .WrapText = False
  296.         .Orientation = 0
  297.         .AddIndent = False
  298.         .IndentLevel = 0
  299.         .ShrinkToFit = False
  300.         .ReadingOrder = xlContext
  301.         .MergeCells = False
  302.     End With
  303.     Selection.Merge
  304.     Range("I3:I8").Select
  305.     With Selection
  306.         .HorizontalAlignment = xlCenter
  307.         .VerticalAlignment = xlBottom
  308.         .WrapText = False
  309.         .Orientation = 0
  310.         .AddIndent = False
  311.         .IndentLevel = 0
  312.         .ShrinkToFit = False
  313.         .ReadingOrder = xlContext
  314.         .MergeCells = False
  315.     End With
  316.     Selection.Merge
  317.     Range("D9:D14").Select
  318.     With Selection
  319.         .HorizontalAlignment = xlCenter
  320.         .VerticalAlignment = xlBottom
  321.         .WrapText = False
  322.         .Orientation = 0
  323.         .AddIndent = False
  324.         .IndentLevel = 0
  325.         .ShrinkToFit = False
  326.         .ReadingOrder = xlContext
  327.         .MergeCells = False
  328.     End With
  329.     Selection.Merge
  330.     Range("E9:E14").Select
  331.     With Selection
  332.         .HorizontalAlignment = xlCenter
  333.         .VerticalAlignment = xlBottom
  334.         .WrapText = False
  335.         .Orientation = 0
  336.         .AddIndent = False
  337.         .IndentLevel = 0
  338.         .ShrinkToFit = False
  339.         .ReadingOrder = xlContext
  340.         .MergeCells = False
  341.     End With
  342.     Selection.Merge
  343.     Range("F9:F14").Select
  344.     With Selection
  345.         .HorizontalAlignment = xlCenter
  346.         .VerticalAlignment = xlBottom
  347.         .WrapText = False
  348.         .Orientation = 0
  349.         .AddIndent = False
  350.         .IndentLevel = 0
  351.         .ShrinkToFit = False
  352.         .ReadingOrder = xlContext
  353.         .MergeCells = False
  354.     End With
  355.     Selection.Merge
  356.     Range("G9:G14").Select
  357.     With Selection
  358.         .HorizontalAlignment = xlCenter
  359.         .VerticalAlignment = xlBottom
  360.         .WrapText = False
  361.         .Orientation = 0
  362.         .AddIndent = False
  363.         .IndentLevel = 0
  364.         .ShrinkToFit = False
  365.         .ReadingOrder = xlContext
  366.         .MergeCells = False
  367.     End With
  368.     Selection.Merge
  369.     Range("H9:H14").Select
  370.     With Selection
  371.         .HorizontalAlignment = xlCenter
  372.         .VerticalAlignment = xlBottom
  373.         .WrapText = False
  374.         .Orientation = 0
  375.         .AddIndent = False
  376.         .IndentLevel = 0
  377.         .ShrinkToFit = False
  378.         .ReadingOrder = xlContext
  379.         .MergeCells = False
  380.     End With
  381.     Selection.Merge
  382.     Range("I9:I14").Select
  383.     With Selection
  384.         .HorizontalAlignment = xlCenter
  385.         .VerticalAlignment = xlBottom
  386.         .WrapText = False
  387.         .Orientation = 0
  388.         .AddIndent = False
  389.         .IndentLevel = 0
  390.         .ShrinkToFit = False
  391.         .ReadingOrder = xlContext
  392.         .MergeCells = False
  393.     End With
  394.     Selection.Merge
  395.     Range("A2").Select
  396.     Selection.Copy
  397.     Range("D9:D14").Select
  398.     ActiveSheet.Paste
  399.     Range("F3:F8").Select
  400.     ActiveSheet.Paste
  401.     Range("A3").Select
  402.     Application.CutCopyMode = False
  403.     Selection.Copy
  404.     Range("G9:G14").Select
  405.     ActiveSheet.Paste
  406.     Range("H3:H8").Select
  407.     ActiveSheet.Paste
  408.     Range("A4").Select
  409.     Application.CutCopyMode = False
  410.     Selection.Copy
  411.     Range("D3:D8").Select
  412.     ActiveSheet.Paste
  413.     Range("H9:H14").Select
  414.     ActiveSheet.Paste
  415.     Range("A5").Select
  416.     Application.CutCopyMode = False
  417.     Selection.Copy
  418.     Range("G3:G8").Select
  419.     ActiveSheet.Paste
  420.     Range("F9:F14").Select
  421.     ActiveSheet.Paste
  422.     Range("A6").Select
  423.     Application.CutCopyMode = False
  424.     Selection.Copy
  425.     Range("E9:E14").Select
  426.     Application.CutCopyMode = False
  427.     Selection.Copy
  428.     Range("A5").Select
  429.     Application.CutCopyMode = False
  430.     Selection.Copy
  431.     Range("A6").Select
  432.     Application.CutCopyMode = False
  433.     Selection.Copy
  434.     Range("E9:E14").Select
  435.     ActiveSheet.Paste
  436.     Range("I3:I8").Select
  437.     ActiveSheet.Paste
  438.     Range("A7").Select
  439.     Application.CutCopyMode = False
  440.     Selection.Copy
  441.     Range("E3:E8").Select
  442.     ActiveSheet.Paste
  443.     Range("I9:I14").Select
  444.     ActiveSheet.Paste
  445.     Application.CutCopyMode = False
  446.     With Selection.Interior
  447.         .Pattern = xlSolid
  448.         .PatternColorIndex = xlAutomatic
  449.         .ThemeColor = xlThemeColorAccent6
  450.         .TintAndShade = -0.499984740745262
  451.         .PatternTintAndShade = 0
  452.     End With
  453.     Range("E3:E8").Select
  454.     With Selection.Interior
  455.         .Pattern = xlSolid
  456.         .PatternColorIndex = xlAutomatic
  457.         .ThemeColor = xlThemeColorAccent6
  458.         .TintAndShade = -0.499984740745262
  459.         .PatternTintAndShade = 0
  460.     End With
  461.     Range("D3:D8").Select
  462.     With Selection.Interior
  463.         .Pattern = xlSolid
  464.         .PatternColorIndex = xlAutomatic
  465.         .Color = 65535
  466.         .TintAndShade = 0
  467.         .PatternTintAndShade = 0
  468.     End With
  469.     Range("H9:H14").Select
  470.     With Selection.Interior
  471.         .Pattern = xlSolid
  472.         .PatternColorIndex = xlAutomatic
  473.         .Color = 65535
  474.         .TintAndShade = 0
  475.         .PatternTintAndShade = 0
  476.     End With
  477.     Range("I3:I8").Select
  478.     With Selection.Interior
  479.         .Pattern = xlSolid
  480.         .PatternColorIndex = xlAutomatic
  481.         .ThemeColor = xlThemeColorDark2
  482.         .TintAndShade = -0.499984740745262
  483.         .PatternTintAndShade = 0
  484.     End With
  485.     With Selection.Interior
  486.         .Pattern = xlSolid
  487.         .PatternColorIndex = xlAutomatic
  488.         .ThemeColor = xlThemeColorDark2
  489.         .TintAndShade = -0.499984740745262
  490.         .PatternTintAndShade = 0
  491.     End With
  492.     Range("E9:E14").Select
  493.     With Selection.Interior
  494.         .Pattern = xlSolid
  495.         .PatternColorIndex = xlAutomatic
  496.         .ThemeColor = xlThemeColorDark2
  497.         .TintAndShade = -0.499984740745262
  498.         .PatternTintAndShade = 0
  499.     End With
  500.     Range("F3:F8").Select
  501.     With Selection.Interior
  502.         .Pattern = xlSolid
  503.         .PatternColorIndex = xlAutomatic
  504.         .ThemeColor = xlThemeColorAccent5
  505.         .TintAndShade = -0.249977111117893
  506.         .PatternTintAndShade = 0
  507.     End With
  508.     Range("D9:D14").Select
  509.     With Selection.Interior
  510.         .Pattern = xlSolid
  511.         .PatternColorIndex = xlAutomatic
  512.         .ThemeColor = xlThemeColorAccent5
  513.         .TintAndShade = -0.249977111117893
  514.         .PatternTintAndShade = 0
  515.     End With
  516.     Range("G3:G8").Select
  517.     With Selection.Interior
  518.         .Pattern = xlSolid
  519.         .PatternColorIndex = xlAutomatic
  520.         .Color = 10498160
  521.         .TintAndShade = 0
  522.         .PatternTintAndShade = 0
  523.     End With
  524.     With Selection.Interior
  525.         .Pattern = xlSolid
  526.         .PatternColorIndex = xlAutomatic
  527.         .ThemeColor = xlThemeColorAccent6
  528.         .TintAndShade = -0.249977111117893
  529.         .PatternTintAndShade = 0
  530.     End With
  531.     Range("F9:F14").Select
  532.     With Selection.Interior
  533.         .Pattern = xlSolid
  534.         .PatternColorIndex = xlAutomatic
  535.         .ThemeColor = xlThemeColorAccent6
  536.         .TintAndShade = -0.249977111117893
  537.         .PatternTintAndShade = 0
  538.     End With
  539.     Range("G9:G14").Select
  540.     With Selection.Font
  541.         .Color = -6279056
  542.         .TintAndShade = 0
  543.     End With
  544.     With Selection.Interior
  545.         .Pattern = xlSolid
  546.         .PatternColorIndex = xlAutomatic
  547.         .Color = 10498160
  548.         .TintAndShade = 0
  549.         .PatternTintAndShade = 0
  550.     End With
  551.     With Selection.Font
  552.         .ColorIndex = xlAutomatic
  553.         .TintAndShade = 0
  554.     End With
  555.     Range("H3:H8").Select
  556.     With Selection.Interior
  557.         .Pattern = xlSolid
  558.         .PatternColorIndex = xlAutomatic
  559.         .Color = 10498160
  560.         .TintAndShade = 0
  561.         .PatternTintAndShade = 0
  562.     End With
  563.     Range("D3:I14").Select
  564.     Range("I9").Activate
  565.     With Selection
  566.         .HorizontalAlignment = xlCenter
  567.         .VerticalAlignment = xlBottom
  568.         .WrapText = False
  569.         .Orientation = 90
  570.         .AddIndent = False
  571.         .IndentLevel = 0
  572.         .ShrinkToFit = False
  573.         .ReadingOrder = xlContext
  574.     End With
  575.     With Selection
  576.         .HorizontalAlignment = xlCenter
  577.         .VerticalAlignment = xlCenter
  578.         .WrapText = False
  579.         .Orientation = 90
  580.         .AddIndent = False
  581.         .IndentLevel = 0
  582.         .ShrinkToFit = False
  583.         .ReadingOrder = xlContext
  584.     End With
  585.     With Selection
  586.         .HorizontalAlignment = xlGeneral
  587.         .VerticalAlignment = xlCenter
  588.         .WrapText = False
  589.         .Orientation = 90
  590.         .AddIndent = False
  591.         .IndentLevel = 0
  592.         .ShrinkToFit = False
  593.         .ReadingOrder = xlContext
  594.     End With
  595.     With Selection
  596.         .HorizontalAlignment = xlCenter
  597.         .VerticalAlignment = xlCenter
  598.         .WrapText = False
  599.         .Orientation = 90
  600.         .AddIndent = False
  601.         .IndentLevel = 0
  602.         .ShrinkToFit = False
  603.         .ReadingOrder = xlContext
  604.     End With
  605.     With Selection
  606.         .HorizontalAlignment = xlLeft
  607.         .VerticalAlignment = xlCenter
  608.         .WrapText = False
  609.         .Orientation = 90
  610.         .AddIndent = False
  611.         .IndentLevel = 0
  612.         .ShrinkToFit = False
  613.         .ReadingOrder = xlContext
  614.     End With
  615.     With Selection
  616.         .HorizontalAlignment = xlCenter
  617.         .VerticalAlignment = xlCenter
  618.         .WrapText = False
  619.         .Orientation = 90
  620.         .AddIndent = False
  621.         .IndentLevel = 0
  622.         .ShrinkToFit = False
  623.         .ReadingOrder = xlContext
  624.     End With
  625.     With Selection
  626.         .HorizontalAlignment = xlGeneral
  627.         .VerticalAlignment = xlCenter
  628.         .WrapText = False
  629.         .Orientation = 90
  630.         .AddIndent = False
  631.         .IndentLevel = 0
  632.         .ShrinkToFit = False
  633.         .ReadingOrder = xlContext
  634.     End With
  635.     With Selection
  636.         .HorizontalAlignment = xlCenter
  637.         .VerticalAlignment = xlCenter
  638.         .WrapText = False
  639.         .Orientation = 90
  640.         .AddIndent = False
  641.         .IndentLevel = 0
  642.         .ShrinkToFit = False
  643.         .ReadingOrder = xlContext
  644.     End With
  645.     With Selection
  646.         .HorizontalAlignment = xlCenter
  647.         .VerticalAlignment = xlCenter
  648.         .WrapText = False
  649.         .Orientation = 90
  650.         .AddIndent = False
  651.         .IndentLevel = 0
  652.         .ShrinkToFit = False
  653.         .ReadingOrder = xlContext
  654.     End With
  655.     With Selection
  656.         .HorizontalAlignment = xlGeneral
  657.         .VerticalAlignment = xlCenter
  658.         .WrapText = False
  659.         .Orientation = 90
  660.         .AddIndent = False
  661.         .IndentLevel = 0
  662.         .ShrinkToFit = False
  663.         .ReadingOrder = xlContext
  664.     End With
  665.     With Selection
  666.         .HorizontalAlignment = xlGeneral
  667.         .VerticalAlignment = xlCenter
  668.         .WrapText = False
  669.         .Orientation = 90
  670.         .AddIndent = False
  671.         .IndentLevel = 0
  672.         .ShrinkToFit = False
  673.         .ReadingOrder = xlContext
  674.     End With
  675.     With Selection
  676.         .HorizontalAlignment = xlCenter
  677.         .VerticalAlignment = xlCenter
  678.         .WrapText = False
  679.         .Orientation = 90
  680.         .AddIndent = False
  681.         .IndentLevel = 0
  682.         .ShrinkToFit = False
  683.         .ReadingOrder = xlContext
  684.     End With
  685.     With Selection
  686.         .HorizontalAlignment = xlGeneral
  687.         .VerticalAlignment = xlCenter
  688.         .WrapText = False
  689.         .Orientation = 90
  690.         .AddIndent = False
  691.         .IndentLevel = 0
  692.         .ShrinkToFit = False
  693.         .ReadingOrder = xlContext
  694.     End With
  695.     With Selection
  696.         .HorizontalAlignment = xlGeneral
  697.         .VerticalAlignment = xlCenter
  698.         .WrapText = False
  699.         .Orientation = 90
  700.         .AddIndent = False
  701.         .IndentLevel = 0
  702.         .ShrinkToFit = False
  703.         .ReadingOrder = xlContext
  704.     End With
  705.     With Selection
  706.         .HorizontalAlignment = xlCenter
  707.         .VerticalAlignment = xlCenter
  708.         .WrapText = False
  709.         .Orientation = 90
  710.         .AddIndent = False
  711.         .IndentLevel = 0
  712.         .ShrinkToFit = False
  713.         .ReadingOrder = xlContext
  714.     End With
  715.     With Selection
  716.         .HorizontalAlignment = xlGeneral
  717.         .VerticalAlignment = xlCenter
  718.         .WrapText = False
  719.         .Orientation = 90
  720.         .AddIndent = False
  721.         .IndentLevel = 0
  722.         .ShrinkToFit = False
  723.         .ReadingOrder = xlContext
  724.     End With
  725.     With Selection
  726.         .HorizontalAlignment = xlGeneral
  727.         .VerticalAlignment = xlCenter
  728.         .WrapText = False
  729.         .Orientation = 90
  730.         .AddIndent = False
  731.         .IndentLevel = 0
  732.         .ShrinkToFit = False
  733.         .ReadingOrder = xlContext
  734.     End With
  735.     With Selection
  736.         .HorizontalAlignment = xlCenter
  737.         .VerticalAlignment = xlCenter
  738.         .WrapText = False
  739.         .Orientation = 90
  740.         .AddIndent = False
  741.         .IndentLevel = 0
  742.         .ShrinkToFit = False
  743.         .ReadingOrder = xlContext
  744.     End With
  745.     With Selection
  746.         .HorizontalAlignment = xlGeneral
  747.         .VerticalAlignment = xlCenter
  748.         .WrapText = False
  749.         .Orientation = 90
  750.         .AddIndent = False
  751.         .IndentLevel = 0
  752.         .ShrinkToFit = False
  753.         .ReadingOrder = xlContext
  754.     End With
  755.     With Selection
  756.         .HorizontalAlignment = xlGeneral
  757.         .VerticalAlignment = xlCenter
  758.         .WrapText = False
  759.         .Orientation = 90
  760.         .AddIndent = False
  761.         .IndentLevel = 0
  762.         .ShrinkToFit = False
  763.         .ReadingOrder = xlContext
  764.     End With
  765.     With Selection
  766.         .HorizontalAlignment = xlCenter
  767.         .VerticalAlignment = xlCenter
  768.         .WrapText = False
  769.         .Orientation = 90
  770.         .AddIndent = False
  771.         .IndentLevel = 0
  772.         .ShrinkToFit = False
  773.         .ReadingOrder = xlContext
  774.     End With
  775.     With Selection
  776.         .HorizontalAlignment = xlGeneral
  777.         .VerticalAlignment = xlCenter
  778.         .WrapText = False
  779.         .Orientation = 90
  780.         .AddIndent = False
  781.         .IndentLevel = 0
  782.         .ShrinkToFit = False
  783.         .ReadingOrder = xlContext
  784.     End With
  785.     With Selection
  786.         .HorizontalAlignment = xlGeneral
  787.         .VerticalAlignment = xlCenter
  788.         .WrapText = False
  789.         .Orientation = 90
  790.         .AddIndent = False
  791.         .IndentLevel = 0
  792.         .ShrinkToFit = False
  793.         .ReadingOrder = xlContext
  794.     End With
  795.     With Selection
  796.         .HorizontalAlignment = xlCenter
  797.         .VerticalAlignment = xlCenter
  798.         .WrapText = False
  799.         .Orientation = 90
  800.         .AddIndent = False
  801.         .IndentLevel = 0
  802.         .ShrinkToFit = False
  803.         .ReadingOrder = xlContext
  804.     End With
  805.     With Selection
  806.         .HorizontalAlignment = xlGeneral
  807.         .VerticalAlignment = xlCenter
  808.         .WrapText = False
  809.         .Orientation = 90
  810.         .AddIndent = False
  811.         .IndentLevel = 0
  812.         .ShrinkToFit = False
  813.         .ReadingOrder = xlContext
  814.     End With
  815.     With Selection
  816.         .HorizontalAlignment = xlCenter
  817.         .VerticalAlignment = xlCenter
  818.         .WrapText = False
  819.         .Orientation = 90
  820.         .AddIndent = False
  821.         .IndentLevel = 0
  822.         .ShrinkToFit = False
  823.         .ReadingOrder = xlContext
  824.     End With
  825.     With Selection
  826.         .HorizontalAlignment = xlGeneral
  827.         .VerticalAlignment = xlCenter
  828.         .WrapText = False
  829.         .Orientation = 90
  830.         .AddIndent = False
  831.         .IndentLevel = 0
  832.         .ShrinkToFit = False
  833.         .ReadingOrder = xlContext
  834.     End With
  835.     With Selection
  836.         .HorizontalAlignment = xlCenter
  837.         .VerticalAlignment = xlCenter
  838.         .WrapText = False
  839.         .Orientation = 90
  840.         .AddIndent = False
  841.         .IndentLevel = 0
  842.         .ShrinkToFit = False
  843.         .ReadingOrder = xlContext
  844.     End With
  845.     Selection.Font.Bold = True
  846.     ActiveWorkbook.Save
  847.     Selection.Borders(xlDiagonalDown).LineStyle = xlNone
  848.     Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  849.     With Selection.Borders(xlEdgeLeft)
  850.         .LineStyle = xlContinuous
  851.         .ColorIndex = 0
  852.         .TintAndShade = 0
  853.         .Weight = xlThin
  854.     End With
  855.     With Selection.Borders(xlEdgeTop)
  856.         .LineStyle = xlContinuous
  857.         .ColorIndex = 0
  858.         .TintAndShade = 0
  859.         .Weight = xlThin
  860.     End With
  861.     With Selection.Borders(xlEdgeBottom)
  862.         .LineStyle = xlContinuous
  863.         .ColorIndex = 0
  864.         .TintAndShade = 0
  865.         .Weight = xlThin
  866.     End With
  867.     With Selection.Borders(xlEdgeRight)
  868.         .LineStyle = xlContinuous
  869.         .ColorIndex = 0
  870.         .TintAndShade = 0
  871.         .Weight = xlThin
  872.     End With
  873.     With Selection.Borders(xlInsideVertical)
  874.         .LineStyle = xlContinuous
  875.         .ColorIndex = 0
  876.         .TintAndShade = 0
  877.         .Weight = xlThin
  878.     End With
  879.     With Selection.Borders(xlInsideHorizontal)
  880.         .LineStyle = xlContinuous
  881.         .ColorIndex = 0
  882.         .TintAndShade = 0
  883.         .Weight = xlThin
  884.     End With
  885.     Range("G9:G14").Select
  886.     ActiveWorkbook.Save
  887.     Columns("D:I").Select
  888.     Selection.ColumnWidth = 21.43
  889.     Range("D2:I2").Select
  890.     With Selection
  891.         .HorizontalAlignment = xlCenter
  892.         .VerticalAlignment = xlBottom
  893.         .WrapText = False
  894.         .Orientation = 0
  895.         .AddIndent = False
  896.         .IndentLevel = 0
  897.         .ShrinkToFit = False
  898.         .ReadingOrder = xlContext
  899.         .MergeCells = False
  900.     End With
  901.     Range("A1").Select
  902. End Sub
  903.  
  904. Rem Attribute VBA_ModuleType=VBAModule
  905. Option VBASupport 1
  906. Sub Värvi(n As Integer)
  907.     Do
  908.         ActiveCell.Rows("1:1").EntireRow.Select
  909.         With Selection.Interior
  910.             .Pattern = xlSolid
  911.             .PatternColorIndex = xlAutomatic
  912.             .ThemeColor = xlThemeColorAccent6
  913.             .TintAndShade = -0.249977111117893
  914.             .PatternTintAndShade = 0
  915.         End With
  916.         ActiveCell.Offset(1, 0).Rows("1:1").EntireRow.Select
  917.         With Selection.Interior
  918.             .Pattern = xlSolid
  919.             .PatternColorIndex = xlAutomatic
  920.             .ThemeColor = xlThemeColorAccent5
  921.             .TintAndShade = -0.249977111117893
  922.             .PatternTintAndShade = 0
  923.         End With
  924.         ActiveCell.Offset(1, 0).Rows("1:1").EntireRow.Select
  925.         With Selection.Interior
  926.             .Pattern = xlSolid
  927.             .PatternColorIndex = xlAutomatic
  928.             .ThemeColor = xlThemeColorAccent4
  929.             .TintAndShade = -0.249977111117893
  930.             .PatternTintAndShade = 0
  931.         End With
  932.         ActiveCell.Offset(1, 0).Rows("1:1").EntireRow.Select
  933.         n = n - 1
  934.     Loop While n > 0
  935. End Sub
  936.  
  937. Sub VärviSisend()
  938.     Dim sisend As String, kordi As Integer
  939.     sisend = InputBox("Mitu korda värvin", "Värvi!")
  940.     If sisend = "" Then
  941.         MsgBox ("Palun sisesta midagi!")
  942.         VärviSisend
  943.     Else
  944.         kordi = CInt(sisend)
  945.         Värvi (kordi)
  946.     End If
  947. End Sub
  948.  
  949. Rem Attribute VBA_ModuleType=VBAModule
  950. Option VBASupport 1
  951. ' antud kera raadius, leiab selle kera ruumala
  952. ' @param r kera raadius
  953. Function KeraRuumala(r As Double) As Double
  954.     KeraRuumala = (4 / 3#) * 3.1415926 * (r ^ 3)
  955. End Function
  956.  
  957. ' antud kera raadius, leiab selle kera ruumala
  958. ' @param r kera raadius
  959. Function KeraPindala(r As Double) As Double
  960.     KeraPindala = 4 * 3.1415926 * (r ^ 2)
  961. End Function
  962.  
  963. ' kontrollib, kas arv on algarv, jagades seda korduvalt
  964. ' läbi iga täisarvuga 2st selle arvuni
  965. ' funktsiooni definitsioon
  966. Function OnAlgarv(arv As Integer) As Boolean
  967.     ' muutuja dekl
  968.    Dim i As Integer
  969.     ' väärtuse andmine
  970.    i = 2
  971.     OnAlgarv = True
  972.     ' alusta tsüklit
  973.    Do
  974.         ' kui arv jagub i-ga
  975.        If arv / i = arv \ i Then
  976.             OnAlgarv = False
  977.         End If
  978.         ' järgmine täisarv
  979.        i = i + 1
  980.     ' tsükkel käib kuni tingimused
  981.    Loop While i < arv And OnAlgarv = True
  982. ' funktsiooni lõpp
  983. End Function
  984.  
  985. Function PallidToText(pallid As Integer) As String
  986.     Dim d As New Dictionary
  987.     d(0) = "tuulevaikus"
  988.     d(1) = "vaikne tuul"
  989.     d(2) = "kerge tuul"
  990.     d(3) = "nõrk tuul"
  991.     d(4) = "mõõdukas tuul"
  992.     d(5) = "kaunis tugev tuul"
  993.     d(6) = "tugev tuul"
  994.     d(7) = "vali tuul"
  995.     d(8) = "tormine tuul"
  996.     d(9) = "torm"
  997.     d(10) = "tugev torm"
  998.     d(11) = "maru"
  999.     d(12) = "orkaan"
  1000.     PallidToText = d(pallid)
  1001. End Function
  1002.  
  1003. Function EnergiaHulk(ainetyyp As String, m As Double, t1 As Double, t2 As Double) As Double
  1004.     Dim erisoojus As Double
  1005.     erisoojus = AineErisoojus(ainetyyp)
  1006.     EnergiaHulk = erisoojus * m * (t2 - t1)
  1007. End Function
  1008.  
  1009. Function AineErisoojus(ainetyyp As String) As Double
  1010.     Dim d As New Dictionary
  1011.     d("Vesi") = 4.1911
  1012.     d("Jää") = 2.093
  1013.     d("Piim") = 3.936
  1014.     d("Raud") = 0.502
  1015.     d("Rasv") = 0.671
  1016.     d("Õli") = 1.779
  1017.     d("Kumm") = 1.424
  1018.     AineErisoojus = d(ainetyyp)
  1019. End Function
  1020.  
  1021. ' leiab fibonacci arve
  1022. ' iga järgmine fibonacci arv on summa eelmisest kahest
  1023. Function fibonacci(n As Integer) As Integer
  1024.     ' vigase sisendi korral anna veaväärtus
  1025.    If n < 0 Then
  1026.         fibonacci = -1
  1027.     End If
  1028.     ' nullis ja esimene fibonacci arv on 1
  1029.    If n = 0 Or n = 1 Then
  1030.         fibonacci = 1
  1031.     Else
  1032.         ' rekurseerides leia arv kui summa eelmisest kahest
  1033.        fibonacci = fibonacci(n - 1) + fibonacci(n - 2)
  1034.     End If
  1035. End Function
Advertisement
Add Comment
Please, Sign In to add comment