Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
71
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.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28. Dim ddv() As Integer
  29. Dim s() As Integer
  30.  
  31. Sub PROJ()
  32.     Dim i As Integer, j As Integer, c As Integer, ca As Integer, n As Integer
  33.     Dim ss(1 To 6, 1 To 8) As Single
  34.     'Ugotovimo, v katerih stolpcih so podatki
  35.     c = Cells(1, 1).Value
  36.     ca = c + 24
  37.     n = Cells(8, c + 11).Value
  38.     If n < 1 Or n > 5 Then
  39.         MsgBox "Predvideli smo samo pet simulacij!", 48, "Opozorilo"
  40.         Exit Sub
  41.     End If
  42.     j = 0
  43.     Do
  44.         j = j + 1
  45.         ss(j, 7) = Cells(j + 11, ca).Value
  46.     Loop Until j = 6
  47.     'Napolnimo prostor v arrayih z vrednostmi
  48.     ss(1, 1) = Cells(ss(1, 7), c).Value
  49.     ss(2, 1) = Cells(ss(2, 7), c).Value
  50.     ss(3, 1) = Cells(ss(3, 7), c).Value
  51.     i = 1
  52.     Do
  53.         i = i + 1
  54.         j = 0
  55.         Do
  56.             j = j + 1
  57.             ss(j, i) = Cells(ss(j, 7), c + i + 11).Value
  58.         Loop Until j = 6
  59.     Loop Until i = 6
  60.     'Pojdimo na list Simulacije in tam popravimo tabele in grafe
  61.     Sheets("Simulacije").Select
  62.     ss(1, 8) = 5
  63.     ss(2, 8) = 32
  64.     ss(3, 8) = 57
  65.     ss(4, 8) = 84
  66.     ss(5, 8) = 111
  67.     ss(6, 8) = 138
  68.     j = 0
  69.     Do
  70.         j = j + 1
  71.         i = 0
  72.         Do
  73.             i = i + 1
  74.             Cells(ss(j, 8) + n, i + 1).Value = ss(j, i)
  75.         Loop Until i = 6
  76.     Loop Until j = 6
  77.     Sheets("Projekcije").Select
  78. End Sub
  79.  
  80. Sub ADD()
  81.     Dim r As Integer, tip As Integer, c As Integer, ca As Integer, n As Integer, _
  82.         k As Integer, d As Integer, ex3 As Single, rfirst As Integer, rlast As Integer, _
  83.         nrows As Integer, i As Integer, ddvtip As Integer, ddvrow As Integer
  84.     'Ugotovimo, v kateri vrsti se nahajamo
  85.     r = ActiveCell.Row
  86.     'Ugotovimo, v katerih stolpcih so podatki
  87.     c = Cells(1, 1).Value
  88.     ca = c + 23
  89.     'Ali je tu dovoljeno izvajati ta makro?
  90.     tip = Cells(r, ca + 4).Value
  91.     If tip <> 1 And tip <> 3 Then
  92.         MsgBox "Dodajanje na tem mestu ni predvideno!", 48, "Opozorilo"
  93.         Exit Sub
  94.     End If
  95.     ActiveSheet.Unprotect
  96.     'Ugotovimo vrste, ki nas zanimajo
  97.     Do Until Cells(r, ca).Value = tip
  98.         r = r - 1
  99.     Loop
  100.     rfirst = r
  101.     ex3 = 0
  102.     If tip = 3 Then ex3 = -1
  103.     n = Cells(r, ca + 1).Value
  104.     k = Cells(r, ca + 2).Value
  105.     d = Cells(r, ca + 3).Value
  106.     ddvtip = Cells(r, ca + 5).Value
  107.     ddvrow = Cells(r, ca + 6).Value
  108.     ReDim s(1 To n)
  109.     i = 0
  110.     Do
  111.         r = r + 1
  112.         If Cells(r, ca).Value = 2 * tip Then
  113.             i = i + 1
  114.             s(i) = r
  115.         End If
  116.     Loop Until (Cells(r, ca).Value <= tip) And (Cells(r, ca).Value <> 0)
  117.     rlast = r
  118.     'Vrinemo toliko vrst, kot jih je v zadnjem bloku
  119.     nrows = rlast - s(n)
  120.     Rows(rlast & ":" & rlast + nrows - 1).Select
  121.     Application.CutCopyMode = False
  122.     Selection.Insert Shift:=xlDown
  123.     'Oznaèimo vrste za kopiranje in jih skopiramo
  124.     Rows(s(n) & ":" & rlast - 1).Select
  125.     Selection.Copy
  126.     Rows(rlast & ":" & rlast + nrows - 1).Select
  127.     ActiveSheet.Paste
  128.     'Popravimo podatke o osnovi
  129.     n = n + 1
  130.     Cells(rfirst, ca + 1).Value = n
  131.     ReDim Preserve s(1 To n)
  132.     s(n) = rlast
  133.     'Popravimo formule v osnovi
  134.     Call NoveFormule(c, n, k, d, rfirst, ex3, ddvtip, ddvrow)
  135.     'Naslednji del je namenjen le dodajanju proizvodov; pozor: kriterij k=7
  136.     If k = 7 Then
  137.         r = rlast
  138.         Do
  139.             r = r + 1
  140.         Loop Until Cells(r, ca) = 7
  141.         r = r + n - 1
  142.         Rows(r & ":" & r).Select
  143.         Application.CutCopyMode = False
  144.         Selection.Insert Shift:=xlDown
  145.         Rows(r - 1 & ":" & r - 1).Select
  146.         Selection.Copy
  147.         Rows(r & ":" & r).Select
  148.         ActiveSheet.Paste
  149.         Application.CutCopyMode = False
  150.         Cells(r, c + 1).FormulaR1C1 = "=R[" & s(n) + 4 - r & "]C/(R31C+R38C+R41C)*100"
  151.         Cells(r, c + 1).Select
  152.                 Selection.Copy
  153.         Range(Cells(r, c + 2), Cells(r, c + 17)).Select
  154.         ActiveSheet.Paste
  155.         Application.CutCopyMode = False
  156.         'Še graf popravimo...
  157.         ActiveSheet.ChartObjects("Chart 14").Activate
  158.         fo = "R" & r & "C" & c + 1 & ":R" & r & "C" & c + 17
  159.         fo = "='Projekcije'!" & fo
  160.         fo = Application.ConvertFormula(Formula:=fo, fromReferenceStyle:=xlR1C1, toReferenceStyle:=xlA1)
  161.         ActiveChart.SeriesCollection.ADD Source:=fo, _
  162.             Rowcol:=xlRows, SeriesLabels:=False, CategoryLabels:=False, Replace:=False
  163.         ActiveChart.SeriesCollection(n + 2).Select
  164.         With ActiveChart.SeriesCollection(n + 2)
  165.             .Name = "=Projekcije!R" & r & "C" & c - 1
  166.         End With
  167.         ActiveWindow.Visible = False
  168.         Cells(s(n), c).Select
  169.     End If
  170.     ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
  171. End Sub
  172.  
  173. Sub DEL()
  174.     Dim r As Integer, tip As Integer, c As Integer, ca As Integer, n As Integer, _
  175.         k As Integer, d As Integer, ex3 As Single, rfirst As Integer, rlast As Integer, _
  176.         nrows As Integer, i As Integer, ddvtip As Integer, ddvrow As Integer
  177.     'A si zihr?
  178.     response = MsgBox("Ali zares zbrisem zadnjega izmed blokov?", 36, "Brisanje")
  179.     If response = 7 Then Exit Sub
  180.     'Ugotovimo, v kateri vrsti se nahajamo
  181.     r = ActiveCell.Row
  182.     'Ugotovimo, v katerih stolpcih so podatki
  183.     c = Cells(1, 1).Value
  184.     ca = c + 23
  185.     'Ali je tu dovoljeno izvajati ta makro?
  186.     tip = Cells(r, ca + 4).Value
  187.     If tip <> 1 And tip <> 3 Then
  188.         MsgBox "Brisanje na tem mestu ni predvideno!", 48, "Opozorilo"
  189.         Exit Sub
  190.     End If
  191.     ActiveSheet.Unprotect
  192.     'Ugotovimo vrste, ki nas zanimajo
  193.     Do Until Cells(r, ca).Value = tip
  194.         r = r - 1
  195.     Loop
  196.     rfirst = r
  197.     ex3 = 0
  198.     If tip = 3 Then ex3 = -1
  199.     n = Cells(r, ca + 1).Value
  200.     'Ali je ta primerek zadnji te osnove
  201.     If n = 1 Then
  202.         MsgBox "Brisanje zadnjega preostalega bloka ni dovoljeno!", 48, "Opozorilo"
  203.         Exit Sub
  204.     End If
  205.     k = Cells(r, ca + 2).Value
  206.     d = Cells(r, ca + 3).Value
  207.     ddvtip = Cells(r, ca + 5).Value
  208.     ddvrow = Cells(r, ca + 6).Value
  209.     ReDim s(1 To n)
  210.     i = 0
  211.     Do
  212.         r = r + 1
  213.         If Cells(r, ca).Value = 2 * tip Then
  214.             i = i + 1
  215.             s(i) = r
  216.         End If
  217.     Loop Until (Cells(r, ca).Value <= tip) And (Cells(r, ca).Value <> 0)
  218.     rlast = r
  219.     'Bri[emo zadnjega od blokov
  220.     Rows(s(n) & ":" & rlast - 1).Select
  221.     Selection.Delete Shift:=xlUp
  222.     'Popravimo podatke o osnovi
  223.     n = n - 1
  224.     Cells(rfirst, ca + 1).Value = n
  225.     ReDim Preserve s(1 To n)
  226.     'Popravimo formule v osnovi
  227.     Call NoveFormule(c, n, k, d, rfirst, ex3, ddvtip, ddvrow)
  228.     'Naslednji del je namenjen le brisanju proizvodov; pozor: kriterij k=7
  229.     If k = 7 Then
  230.         r = rfirst
  231.         Do
  232.             r = r + 1
  233.         Loop Until Cells(r, ca) = 7
  234.         r = r + n
  235.         Rows(r & ":" & r).Select
  236.         Selection.Delete Shift:=xlUp
  237.         ActiveSheet.DrawingObjects("Chart 14").Select
  238.         ActiveSheet.ChartObjects("Chart 14").Activate
  239.         ActiveChart.SeriesCollection(n + 3).Select
  240.         Selection.Delete
  241.         ActiveWindow.Visible = False
  242.         Cells(s(n), c).Select
  243.     End If
  244.     ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
  245. End Sub
  246.  
  247. Sub NoveFormule(ByVal cs As Integer, ByVal ns As Integer, ByVal ks As Integer, ByVal ds As Integer, ByVal rfirsts As Integer, ByVal ex3s As Single, ByVal ddvtips As Integer, ByVal ddvrows As Integer)
  248.     Dim i As Integer, j As Integer
  249.     i = 0
  250.     If ex3s = -1 Then y1 = Cells(rfirsts, cs + 13).FormulaR1C1
  251.     Do
  252.         i = i + 1
  253.         j = 0
  254.         If i = 1 Then
  255.         Do
  256.             j = j + 1
  257.             Cells(rfirsts + ex3s + j, cs).FormulaR1C1 = "=R[" & (s(i) - (rfirsts + ex3s) - 1) + ds & "]C"
  258.         Loop Until j = ks
  259.         End If
  260.         If i > 1 Then
  261.         Do
  262.             j = j + 1
  263.             Cells(rfirsts + ex3s + j, cs).FormulaR1C1 = Cells(rfirsts + ex3s + j, cs).FormulaR1C1 & "+R[" & (s(i) - (rfirsts + ex3s) - 1) + ds & "]C"
  264.         Loop Until j = ks
  265.         End If
  266.     Loop Until i = ns
  267.     Range(Cells(rfirsts + ex3s + 1, cs), Cells(rfirsts + ex3s + ks, cs)).Select
  268.     Selection.Copy
  269.     Range(Cells(rfirsts + ex3s + 1, cs + 1), Cells(rfirsts + ex3s + ks, cs + 17)).Select
  270.     Selection.PasteSpecial Paste:=xlFormulas, Operation:=xlNone, _
  271.         SkipBlanks:=False, Transpose:=False
  272.     Application.CutCopyMode = False
  273.     If ex3s = -1 Then Cells(rfirsts, cs + 13).FormulaR1C1 = y1
  274.     'Popravek formul za izraèun DDV (èe je to v tem bloku ustrezno)
  275.     If ddvtips > 0 Then
  276.         i = 1
  277.         Cells(rfirsts + ddvrows, cs + 1).FormulaR1C1 = "=R[" & (s(i) + ddvtips - 1 - rfirsts - ddvrows) & "]C" & "*R[" & (s(i) + ddvtips - 1 - rfirsts - ddvrows) & "]C" & cs + 18
  278.         If ns > 1 Then
  279.                 Do
  280.                 i = i + 1
  281.                 Cells(rfirsts + ddvrows, cs + 1).FormulaR1C1 = Cells(rfirsts + ddvrows, cs + 1).FormulaR1C1 & "+R[" & (s(i) + ddvtips - 1 - rfirsts - ddvrows) & "]C" & "*R[" & (s(i) + ddvtips - 1 - rfirsts - ddvrows) & "]C" & cs + 18
  282.                 Loop Until i = ns
  283.         End If
  284.         Range(Cells(rfirsts + ddvrows, cs + 1), Cells(rfirsts + ddvrows, cs + 1)).Select
  285.         Selection.Copy
  286.         Range(Cells(rfirsts + ddvrows, cs + 2), Cells(rfirsts + ddvrows, cs + 12)).Select
  287.         Selection.PasteSpecial Paste:=xlFormulas, Operation:=xlNone, _
  288.             SkipBlanks:=False, Transpose:=False
  289.         Range(Cells(rfirsts + ddvrows, cs + 14), Cells(rfirsts + ddvrows, cs + 17)).Select
  290.         Selection.PasteSpecial Paste:=xlFormulas, Operation:=xlNone, _
  291.             SkipBlanks:=False, Transpose:=False
  292.         Application.CutCopyMode = False
  293.     End If
  294.     Cells(s(ns), cs).Select
  295. End Sub
  296.  
  297. Sub Copyright()
  298.     MsgBox "Projekcije 2007 v2" & String(1, 10) & String(1, 10) & "© 1997-2007 Matic Kovaèiè " & String(1, 10) & "© 1997 prof. dr. Aleš Vahèiè" & String(1, 10) & String(1, 10) & "Ekonomska fakulteta, Ljubljana", 64, "Avtorji"
  299. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement