VBA – 3 vjezbe uradjene

Posted: oktobar 17, 2011 in Uncategorized
Oznake:, , ,

VBA – 3 vjezbe uradjene

1. zadatak

Sub praznacelija(opseg As Range)
Dim i As Integer, j As Integer
Dim br As Integer
sum = 0
For i = 1 To opseg.Rows.Count
For j = 1 To opseg.Columns.Count
If opseg.Cells(i, j) = „“ Then
opseg.Cells(i, j) = „prazna“
br = br + 1
End If
Next
Next
MsgBox br
End Sub

praznacelija range(„A1:C5“)

2. zadatak

Sub djeljiv(opseg As Range)
Dim i As Integer, j As Integer
Dim sum As Integer
sum = 0
For i = 1 To opseg.Rows.Count
For j = 1 To opseg.Columns.Count
If IsNumeric(opseg.Cells(i, j)) Then
If opseg.Cells(i, j) > 0 And opseg.Cells(i, j) Mod 3 = 0 Then
sum = sum + 1
End If
End If
Next
Next
MsgBox sum
End Sub

3. zadatak
Sub MaksimalanOboj()
Dim I As Integer, J As Integer
Dim Opseg As Range
Dim Maks As Single, PozVr As Integer, PozKol As Integer, Min As Single
Set Opseg = Range(„A1:D5“)
Maks = Opseg.Cells(1, 1).Value
Min = Opseg.Cells(1, 1).Value
For I = 1 To Opseg.Rows.Count
For J = 1 To Opseg.Columns.Count
If Opseg.Cells(I, J).Value > Maks Then
Maks = Opseg.Cells(I, J).Value
PozVr = I
PozKol = J
End If
Next
Next
If IsNumeric(Opseg.Cells(I, J)) Then
For I = 1 To Opseg.Rows.Count
For J = 1 To Opseg.Columns.Count
If Opseg.Cells(I, J).Value > Maks Then
Maks = Opseg.Cells(I, J).Value
PozVr = I
PozKol = J
End If
Next
Next
For I = 1 To Opseg.Rows.Count
For J = 1 To Opseg.Columns.Count
If Opseg.Cells(I, J).Value < Min Then
Min = Opseg.Cells(I, J).Value
PozVr = I
PozKol = J
End If
Next
Next
Opseg.Cells(PozVr, PozKol).Interior.Color = RGB(0, 0, 255)
MsgBox Maks
Opseg.Cells(PozVr, PozKol).Interior.Color = RGB(255, 0, 0)
MsgBox Min
End If
If Not IsNumeric(Opseg.Cells(I, J)) Then
MsgBox „nema brojeva u opsegu“
End If
End Sub

4. zadatak

Sub Prosljedjivanje(Opseg As Range)
Dim I As Integer, J As Integer
For I = 1 To Opseg.Rows.Count
For J = 1 To Opseg.Columns.Count
If Opseg.Cells(I, J) = „“ Then
Opseg.Cells(I, J).Interior.Color = RGB(255, 0, 0)
ElseIf IsNumeric(Opseg.Cells(I, J)) Then
Opseg.Cells(I, J).Font.Size = 14
Opseg.Cells(I, J).Font.Name = „Calibri“
Else
Opseg.Cells(I, J).Font.Bold = True
Opseg.Cells(I, J).Font.Color = RGB(0, 255, 0)
End If

Next
Next
End Sub

Advertisements

Zatvoreno za komentare.