0% found this document useful (0 votes)
0 views2 pages

macros_code

The document contains five macros written in VBA for Excel. The macros include calculating the area of a triangle, checking if a number is positive, negative, or zero, checking signs in the first 50 values of column A, summing numbers in column A, and generating a 10x10 multiplication table. Each macro performs specific tasks related to data manipulation in Excel worksheets.

Uploaded by

puja.advika24
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views2 pages

macros_code

The document contains five macros written in VBA for Excel. The macros include calculating the area of a triangle, checking if a number is positive, negative, or zero, checking signs in the first 50 values of column A, summing numbers in column A, and generating a 10x10 multiplication table. Each macro performs specific tasks related to data manipulation in Excel worksheets.

Uploaded by

puja.advika24
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

' -------------------------

' Macro 1 – Calculate Area of Triangle


' -------------------------
Sub CalculateTriangleArea()
Dim a As Double, h As Double, P As Double
a = Range("B1").Value
h = Range("B2").Value
P = 0.5 * a * h
Range("B3").Value = P
End Sub

' -------------------------
' Macro 2 – Check Positive, Negative, or Zero (A1)
' -------------------------
Sub CheckSign()
Dim num As Double
num = Range("A1").Value

With Range("A1").Interior
If num > 0 Then
.Color = vbGreen
ElseIf num < 0 Then
.Color = vbRed
Else
.Color = vbWhite
End If
End With
End Sub

' -------------------------
' Macro 3 – Check Signs in Column A (First 50 values)
' -------------------------
Sub CheckColumnSigns()
Dim i As Integer
For i = 1 To 50
If Cells(i, 1).Value > 0 Then
Cells(i, 2).Value = "Positive"
ElseIf Cells(i, 1).Value < 0 Then
Cells(i, 2).Value = "Negative"
Else
Cells(i, 2).Value = "Zero"
End If
Next i
End Sub

' -------------------------
' Macro 4 – Sum Numbers in Column A (First 50 rows)
' -------------------------
Sub SumColumnA()
Dim i As Integer, total As Double
total = 0
For i = 1 To 50
total = total + Cells(i, 1).Value
Next i
MsgBox "The sum of the numbers in column A is: " & total
End Sub

' -------------------------
' Macro 5 – 10x10 Multiplication Table
' -------------------------
Sub MultiplicationTable()
Dim i As Integer, j As Integer
For i = 1 To 10
For j = 1 To 10
Cells(i, j).Value = i * j
Next j
Next i
End Sub

You might also like