You are on page 1of 9

Sub Test() Dim iX As Integer iX = 5 sIme = "Petko" sIme = Cells(1, 1) bPrasanje = Time dPi = 3.

1415926 MsgBox dPi End Sub Sub Test() Dim iX As Integer iX = 15 iX = Cells(1, 1) iY = 20 iY = Cells(2, 1) iSum = Cells(3, 1) = Cells(1, 1) + Cells(2, 1) End Sub Sub promenlivi() Dim ix As Integer Dim iy As Integer Dim iz As Integer ix = 5

iy = 7 iz = 9 Cells(1, 1) = Cells(1, 2) = Cells(1, 3) = MsgBox "x=" & vbCrLf & "y=" vbCrLf & "z="

ix 'Deklariranje vrednost na promenlivi iy iz Cells(1, 1) & _ & Cells(1, 2) & _ & Cells(1, 3)

Dim iSuma As Integer iSuma = ix + iy + iz 'Suma na promenlivite Cells(1, 4) = iSuma MsgBox "Sumata e:" & " " & Cells(1, 4) Dim dProsek As Double dProsek = iSuma / 3 'Prosek na promenlivite Cells(1, 5) = dProsek MsgBox "Prosekot e:" & "" & Cells(1, 5) Dim iOstatok As Integer iOstatok = ix Mod iy 'Ostatok od delenje megu x i y Cells(1, 6) = iOstatok MsgBox "Ostatokot e:" & " " & Cells(1, 6) End Sub

Sub krug() Dim iR As Integer Dim dL As Double Dim dP As Double Dim dPi As Double Pi = 3.141595526 iR = Cells(5, 2) dL = 2 * iR * Pi dP = iR * iR * Pi Cells(6, 2) = dL Cells(7, 2) = dP End Sub Sub pravoagolnik() Dim ia As Integer Dim ib As Integer Dim iL As Integer Dim iP As Integer ia = Cells(9, 2) ib = Cells(10, 2) iL = 2 * (ia + ib) iP = ia * ib Cells(11, 2) = iL Cells(12, 2) = iP End Sub

Sub konus() Dim dR As Double Dim dH As Double Dim dV As Double Dim dB As Double Dim dPi As Double dPi = 3.141595526 dR = Cells(14, 2) dH = Cells(15, 2) dB = dPi * dR * dR dV = dB * dH / 3 Cells(16, 2) = dV End Sub Sub cilindar() Dim dR As Double Dim dH As Double Dim dV As Double Dim dB As Double Dim dPi As Double dPi = 3.141595526 dR = Cells(18, 2) dH = Cells(19, 2) dB = dPi * dR * dR dV = dB * dH Cells(20, 2) = dV End Sub

Sub Podatoci() Dim sIme As String Dim sPrezime As String Dim iRoden As Integer Dim iSega As Integer Dim iGodini As Integer iSega = Cells(8, 5) iRoden = Cells(7, 5) iGodini = iSega - iRoden MsgBox "Studentot" & " " & Cells(5, 5) & " " & Cells(6, 5) & " " & "ima" & " " & iGodini & " " & "godini." End Sub

Sub Zamena_na_2_promenlivi() Dim iA As Integer Dim iB As Integer iA = Cells(11, 5) iB = Cells(12, 5) iA = iA + iB iB = iA - iB iA = iA - iB MsgBox "A=" & iA & "; " & "B=" & " " & iB End Sub Sub Nizi() Worksheets(2).Visible = False Cells(1, 1).Interior.ColorIndex = 4 End Sub Sub Figura() Cells(1, 1).Interior.ColorIndex = 6

Cells(1, Cells(3, Cells(3, Cells(2,

3).Interior.ColorIndex 1).Interior.ColorIndex 3).Interior.ColorIndex 2).Interior.ColorIndex

= = = =

6 6 6 3

Sub Nizi() Dim iArr(4) As iArr(1) = 5 iArr(2) = 3 iArr(3) = 3 iArr(4) = 34 Cells(26, 2) = Cells(27, 2) = Cells(28, 2) = Cells(29, 2) = End Sub

Integer

iArr(1) iArr(2) iArr(3) iArr(4)

Sub Jan_Fev() Dim iProdazba(2, 3) As Integer iProdazba(1, 1) = Cells(17, 5) iProdazba(1, 2) = Cells(17, 6) iProdazba(2, 1) = Cells(18, 5) iProdazba(2, 2) = Cells(18, 6) iProdazba(1, 3) = iProdazba(1, 1) + iProdazba(1, 2) iProdazba(2, 3) = iProdazba(2, 1) + iProdazba(2, 2) Cells(17, 7) = iProdazba(1, 3) Cells(18, 7) = iProdazba(2, 1) End Sub

Sub student() If Cells(1, 1) = 2006 Then MsgBox "ok" End If End Sub Sub student() If Cells(1, 1) = 2006 Then MsgBox "ok" Else MsgBox "No" End If End Sub Sub student() If Cells(1, 1) = 2006 Then MsgBox "2006" ElseIf Cells(1, 1) = 2007 Then MsgBox "2007" End If End Sub Da se napise procedura koja sto ke odredi dali korisnikot ima pravo na glas. Sub student() Dim iGodini As Integer iGodini = Cells(1, 1) If iGodini >= 18 Then MsgBox "Vie nemate glas" End If End Sub

Kreirajte 6 razlicni makroa kade ke gi upotrebite site relacioni operatori. Za sporedba koristete gi keliite vo Excel dokumentot. Sub student() If 5 = 6 Then MsgBox "Ne e tocno" End If End Sub =, <>, <, >, <=, =>. Kreirajte makro koe ke proveri dali prvite tri vrednosti na keliite vo prvata kolona se vo rastecki redosled. Sub student() If Cells(1, 1) < Cells(2, 1) Then If Cells(2, 1) < Cells(3, 1) Then MsgBox "Broevite se rastecki" End If End If End Sub

Sub student() If Cells(1, 1) < Cells(2, 1) Then If Cells(2, 1) < Cells(3, 1) Then MsgBox "Broevite se rastecki" Else MsgBox "Broevite ne se rastecki" End If Else MsgBox "broevite ne se rastecki" End If End Sub Sub student () If Cells(1, 1) < Cells(2, 1) And Cells(2, 1) < Cells(3, 1) MsgBox "Rastecki" Else MsgBox "ne se rastecki" End If Sub student() bUslov1 = Cells(1, 1) < Cells(2, 1) bUslov2 = Cells(2, 1) < Cells(3, 1) If bUslov1 And bUslov2 Then MsgBox "Rastecki"

End If

End Sub Ako korisnikot ima pomalku od 18 godini nemoze da glasa.Ako korisnikot e od 18 do 31 moze da glasa, ako korisnikot e od 31 do 60 godini moze da glasa i da pie, ako e postar od 64 moze da zema penzija. Sub student() Dim iKorisnik As Integer iKorisnik = Cells(1, 1) If iKorisnik < 18 Then MsgBox "Vie nemate glas" ElseIf iKorisnik < 30 Then MsgBox "Moze da glasa" ElseIf iKorisnik < 64 Then MsgBox "Moze da pie" Else MsgBox "Penzija"

End If End Sub Sub student() Dim iKorisnik As Integer Select Case iKorisnik Case Is < 18 MsgBox " Nema pravo na glas" Case Is < 30 MsgBox "Ima pravo na glas" Case Is < 64 MsgBox "Moze Da pie" Case Else MsgBox "penzija" End Select End Sub If Application.IsText(ActiveCell) Then MsgBox "Text"

ElseIf ActiveCell = " " Then MsgBox "Prazna kelija" ElseIf ActiveCell HexFormulla Then MsgBox "Formula" ElseIf Isdate (Active Cell Value) Then MsgBox "Datum" End If End Sub

-------------------------------------------Sub vezba1() Range("A1") = Now iBroj = Range("A3") Range("A3") = iBroj + 1 x = ActiveCell.Row y = ActiveCell.Column MsgBox x & " " & y End Sub Sub vezba3() Worksheets(2).Select End Sub -------------------------------------------Sub vezba4()

-------------------------------------------Sub vezba2() MsgBox Selection.Rows.Count MsgBox Selection.Colum.Count End Sub -------------------------------------------For i = 2 To 8 Step 2 MsgBox i Next i End Sub --------------------------------------------

Dim i As Integer Sub vezba5() i = 4 For i = 4 To 15 Step 4 s = s = 4 Next i ostatok = 15 - s MsgBox ostatok End Sub -------------------------------------------Sub vezba6() Dim i As Integer For i = 1 To 10 s = s + Cells(i, 3) MsgBox s Next i

End Sub -------------------------------------------Sub vezba7() Dim imax As Integer imax = Cells(1, 1) For i = 2 To 10 If imax < Cells(i, 1) Then imax = Cells(i, 1) End If Next i MsgBox imax End Sub -------------------------------------------Sub vezva8() Dim imin As Integer imin = Cells(1, 1) For i = 2 To 10 If imin > Cells(i, 1) Then imin = Cells(i, 1) End If Next i MsgBox imin End Sub

-------------------------------------------Sub vezba9() For i = 1 To Selection.Rows.Count For j = 1 To Selection.Columns.Count MsgBox Selection(i, j) Next j, i End Sub Da se oderdi brojot na sutednti vneseni vo tabelata Sub student() Dim i As Integer i = 0 Do While Cells(i + 1, 1) <> "" i = i + 1 If Cells(i + 1, 2) < 50 Then Cells(i + 1, 3) = 5 End If Loop MsgBox i End Sub Sin,Cos,Tan,Cot Sub student() Dim i As Integer Dim r As Integer r = 2 For i = 0 To 90 Step 15 Cells(r, 1) = i Cells(r, 2) = i * 3.14 / 180 Cells(r, 3) = Math.Sin(Cells(r, 2)) Cells(r, 4) = Math.Cos(Cells(r, 3)) Cells(r, 5) = Math.Tan(Cells(r, 4)) If Cells(r, 5) <> 0 Then Cells(r, 6) = 1 / Cells(r, 5) r = r + 1 Next i End Sub Funkcija Function Pi() As Double Pi = 3.14159562 End Function Sub Test() MsgBox Pi() End Sub Da se napise funkcija koja ke presmeta plostina na krug Function Pi() As Double Pi = 3.14159562 End Function Sub Test() MsgBox pkrug(5.15) End Sub Function pkrug(r As Double) As Double pkrug = r * r * Pi() End Function da se napise funkcija koja vo string ke gi otstrani praznite mesta Sub test() MsgBox OtsraniPrazni(" Srekni Praznici") End Sub Function OtsraniPrazni(sText As String) As String Dim sPriv As String Dim i As Integer sPriv = ""

For i = 1 To Len(sText) MsgBox ("Srekni Praznici") If Mid(sText, i, 1) <> " " Then sPriv = sPriv + Mid(sText, i, 1) End If Next i OtstraniPrazni = sPriv

End Function Da se prikaze slucaen broj Sub Slucaen() Math.Randomize MsgBox Math.Rnd() End Sub Da se generira slucaen broj 0,1,2 Sub Slucaen() Dim i As Integer Math.Randomize i = 10 * Math.Rnd() MsgBox i Mod 3 End Sub Vnesuvanje na iminja ili text Sub Vnesuvanje() Dim sIme As String sIme = InputBox("Vnesi go tvoeto ime") MsgBox sIme End Sub Vnesuvanje na tocni ili pogresni broevi Sub Slucaen() Dim i As Integer Math.Randomize i = 10 * Math.Rnd() x = InputBox("Vnesi go tocniot broj") i = i Mod 3 If i = x Then MsgBox ("Bravo go vnese tocniot broj") Else MsgBox ("Bravo go vnese pogrsniot broj") End If End Sub

Sub Test() Dim fnum As Integer Dim stzFileName As String fnum = FreeFile() stzFileName = "D:\file3.txt" Open stzFileName For Output As fnum Write #fnum, "tekst" Print #fnum, "text" Close #fnum End Sub Da se napravi export vo prvata kolona od excel vo txt file. Sub Test() Dim fnum As Integer Dim stzFileName As String

fnum = FreeFile() stzFileName = "D:\file5.txt" Open stzFileName For Output As fnum i = 1 Do While Cells(i, 1) <> "" Print #fnum, Cells(i, 1) i = i + 1 Loop Close #fnum End Sub Sub Vezba() Dim fnum As Integer Dim stzFileName As String fnum = FreeFile() stzFileName = "D:\file3.csv" Open stzFileName For Output As fnum For i = 1 To 3 Dim sRed As String sRed = "" For j = 1 To 2 sRed = sRed + Cells(i, j) + ";" Next j Print #fnum, sRed Next i Close #fnum End Sub Sub Vezba() Dim sIme As String sIme = InputBox("Vnesi go tvoeto ime") MsgBox "Zdravo" & Ime If MsgBox("Dali ste sigurni?", vbYesNo) = vbYes Then MsgBox "Pritisnavte Yes" Else MsgBox "Vasiot izbor e Ne" End If End Sub Vezbi 2 stext="ab9c" for i=1 To Len (sText) bukva=mid (sText, i, 1) If (bukva >="a" and bukva <="z") or (bukva >= "A" And bukva <="Z") Then brojac=brojac+1 End If

Sub proba() Dim i As Integer Dim j As Integer Dim pris As Integer Dim ots As Integer Dim fnum As Integer Dim strfilename As String

fnum = FreeFile() strfilename = "C:\Brance\File.csv" Open strfilename For Output As fnum

i=2 Do While Cells(i, 1) <> ""

j=2 pris = 0 ots = 0

Do While Cells(i, j) <> ""

If Cells(i, j) = "+" Then pris = pris + 1 Else ots = ots + 1

j=j+1 Loop

Cells(i, j) = pris Cells(i, j + 1) = ots

If Cells(i, j + 1) > 3 Then Print #fnum, Cells(i, 1) & ";" & Cells(i, j + 1)

i=i+1 Loop

Close #fnum

Exit Sub

Greska:

MsgBox Err.Number & " " & Err.Description

End Sub 2. Sub brojki() Dim i As Integer Dim ibrojac As Integer Dim sbukva As String stext = "ab9crttyy" For i = 1 To Len(stext)

sbukva = Mid(stext, i, 1) If (sbukva >= "a" And sbukva <= "z") Or (sbukva >= "A" And sbukva <= "Z") Then ibrojac = ibrojac + 1

End If

Next i MsgBox (ibrojac) End Sub

You might also like