Functions
Function ODDorEVEN(x As Double) As String
Ifx Mod 2 =0 Then
ODDorEVEN = "EVEN"
Else
ODDorEVEN = "ODD"
End If
End Function
Function EVENcheckSHEET1() As String.
If Worksheets(1).Range("D4").Value Mod 2 = 0 Then
EVENcheckSHEET1 = "EVEN"
Else
EVENcheckSHEET:
End If
End Function
Function GRADE(x As Double) As String
fx >= 90 Then
GRADE = "0"
Elself x
GRADE
Elself x
GRADE
Elself x
GRADE
Elself x
GRADE
Else
GRADE = "FAIL"
End If
End Function
Function APPRECIATION(x As String) As String.
Select Case x
Case "0"
APPRECIATION = "Extraordinary"
Case "A"
APPRECIATION = "Excellent"
Case "B"
APPRECIATION = "Very Good”Case "Cc"
APPRECIATION = "GOOD"
Case "D"
APPRECIATION
Case "FAIL"
APPRECIATION
Case Else
APPRECIATION
End Select
End Function
"average"
"POOR"
ONL
Function FACTORIAL(n As Integer) As Integer
Dim ans As Integer
ans=1
Fori=1Ton Step 1
ans = ans *i
Next
FACTORIAL = ans
End Function
Function FIB(x As Integer)
Dim ans As String
Dim a, b As Integer
a=0
b=
ans
Dim iAs Integer
iso
While i< x
ans = ans &"" & CStr(a)
iva
‘Wend
MsgBox (ans)
End Function
Function RANGDIFF(r1 As Range, r2 As Range) As Double
Dim sum1 As Double
Dim sum2 As Double
sum1 = sum2 =0For Each i In r1.Cells
sum = sum! + i.Value
Next
For Each i in r2.Cells
sum2 = sum2 +i.Value
Next
RANGDIFF = Abs(sumi - sum2)
MsgBox RANGDIFF, vbOKOnly, "Result"
End Function
Function GETSQR() As Integer
Dim a As Integer
a= InputBox("Insert a value", "SumApp", 1)
GETSQR=a*a
End Function
Subprocedures / Macros
‘Sub even()
If ActiveCell.Value > 5 Then
Worksheets(2) Activate
Worksheets(2).Range("A1:AS") Select
Selection Value = "EVEN"
ActiveSheet.Cells(10, 1).Select
Selection Value = "Selected using macros”
‘ActiveCell.Offset(0, 1).Value = "Offset(0,1): same row, next column’
End if
End Sub
Sub colorchange()
Dim r As Range
Set r= Selection
For Each in Cells
Ifi>= 90 Then
i.Offset(0, 2).Interior.Colorindex = 24
Elsetfi >= 80 Then
i.Offset(0, 2].Interior.Colorindex = 34
Elsetfi >= 70 Then
iOffset(0, 2).Interior.Color = RGB(25S, 255, 0)
Elselfi >= 60 Then
iOffset(0, 2).Interior.Colorindex = 16Elselfi >= 50 Then
i.Offset(0, 2).Interior.Colorindex = 42
Else
LOffset(0, 2).Interior.Colorindex = 3
End if
Next
End sub
Sub add_date()
* Positive Interal
Datel = CDate("05/jan/2018")
MsgBox ("Line 1 :" & Dateadd("yyyy", 1, Datel))
MsgBox ("Line 2 :" & DateAdd( "a", 1, Datel)
MsgBox ("Line 3 :" & DateAdd("m", 1, Datel)
MsgBox ("Line 4 :" & DateAdd("y", 1, Date1))
MsgBox ("Line 5 :" & DateAdd("é", 1, Datel))
MsgBox ("Line 6 :" & Dateadd("w", 1, Datet})
MsgBox ("Line 7 :" & Dateadd( "ww", 1, Datet))
MsgBox ("Line 8 :" & DateAdd("h", 1, "01-Jan-2013 12:00:00")
MsgBox ("Line 9: & DateAdd("n", 1, "01-Jan-2013 12:00:00")
MsgBox ("Line 10 :" & DateAdd("s", 1, "01-Jan-2013 12:00:00")
" Negative Interval
MsgBox ("Line 11 :" & DateAdd("yyyy", -1, Datel)
MsgBox ("Line 12 :" & DateAdd("q", -1, Date1))
MsgBox ("Line 13 :" & DateAdd("m’, -1, Datel))
MsgBox ("Line 14 :" & DateAdd("y’, -1, Datet))
MsgBox ("Line 15 :" & DateAdd( "a
MsgBox ("Line 16 :" & DateAdd("w"
MsgBox ("Line 17 :" & DateAdd("ww', -1, Datel)
MsgBox ("Line 18 :" & DateAdd("h", -1, "01-Jan-2013 12:00:00"))
MsgBox ("Line 19 :" & DateAdd("n", -1, "01-Jan-2013 12:00:00"))
MsgBox ("Line 20 :" & DateAdd("s", -1, "01-Jan-2013 12:00:00")
End Sub
Sub Date_diffrne()
Dim fromDate As Variant
fromDate = "01-Jan-2017 00:00:00"
Dim toDate As Variant
toDate = Date
MsgBox ("Line 1 :" & Datediff("yyyy", fromDate, toDate))
MsgBox ("Line 2 :" & Datediff("q", fromDate, toDate))MsgBox ("Line 3 :" & Datedifi("m", fromDate, toDate))
MsgBox ("Line 4 :" & Datediff("y", fromDate, toDate))
MsgBox ("Line 5 :" & Datediff("d", fromDate, toDate))
MsgBox ("Line 6 :" & Datediff("w", fromDate, toDate))
MsgBox ("Line 7 :" & Datediff("ww", fromDate, toDate))
MsgBox ("Line 8 :" & Datediff("h", fromDate, toDate))
MsgBox ("Line 9 :" & Datediff("n", fromDate, toDate))
MsgBox ("Line 10: " & Datediff("s", fromDate, toDate)}
End Sub
Sub Date_parts()
Dim Quarter As Variant
Dim DayOfvear As Variant
Dim WeekOfvear As Variant
Date1 = "2013-01-15"
Quarter = DatePart("q", Date1)
MsgBox ("Line 1 :" & Quarter)
DayOfvear = DatePart("y’, Datel)
MsgBox ("Line 2
‘WeekOfvear =
" & DayOfYear)
atePart("ww", Datel)
MsgBox ("Line 3 :" & WeekOfYear)
MsgBox ("Line 4 :" & DatePart("m", Date1))
End Sub
Excursive Programs:
Write a Macro subprocedure to apply a condition on Range based on your login and do formatting
accordingly.