You are on page 1of 5

'Example 1: How To Access The Excel Range And Show The Value Using Message

Box
Sub sbExample1()

'It will display the A5 value in the message Box

MsgBox Range("A5")

'You can also use Cell Object to refer A5 as shwon below:

MsgBox Cells(5, 1) 'Here 5 is Row number and 1 is Column number

End Sub

'Example 4: How To Change The Font Color And Font Size Of A Particular Range
Sub sbExample4()

'You can set the background color using Interior.ColorIndex Property

Range("B1:B10").Font.ColorIndex = 3 ' 3=Red

End Sub

'Example 5: How To Change The Text To Upper Case Or Lower Case


Sub sbExample5()

'You can use UCase function to change the text into Upper Case

Range("C2").Value = UCase(Range("C2").Value)

'You can use LCase function to change the text into Upper Case

Range("C3").Value = LCase(Range("C3").Value)

End Sub
'Example 6: How To Copy Data From One Range To Another Range
Sub sbExample6()

'You can use Copy method

Range("A1:D11").Copy Destination:=Range("H1")

End Sub

'Example 7: How To Select And Activate Worksheet


Sub sbExample7()

'You can use Select Method to select

Sheet2.Select

'You can use Acctivate Method to activate

Sheet1.Activate

End Sub

Option Explicit

Function SumDigits(Number As Variant)

Dim i As Integer

For i = 1 To Len(Number)

If IsNumeric(Mid(Number, i, 1)) Then

SumDigits = SumDigits + Val(Mid(Number, i, 1))

End If

Next i

End Function
Sub Addition()

Dim Add As Integer

Dim var1 As Integer

Dim var2 As Integer

var1 = Range("A2").Value

var2 = Range("B2").Value

Add = var1 + var2

Range("C2").Select

ActiveCell.FormulaR1C1 = Add

End Sub

Function MessageBox_Demo()

'Message Box with just prompt message

Dim a As Integer

MsgBox ("Welcome")

'Message Box with title, yes no and cancel Butttons

a = MsgBox("Do you like blue color?", 3, "Choose options")

' Assume that you press No Button

MsgBox ("The Value of a is " & a)

End Function

Sub Command1_Click()

Dim i As Integer

Dim str As String

str = Text1.Text

i = IsNumeric(str)

If i = 0 Then
Text2.Text = "string data"

Else: Text2.Text = "numeric data"

End If

End Sub

Sub Add_2()

Dim a As Integer

Dim b As Integer

Dim c As Integer

a = 30

b = 20

c=a+b

Range("a2").Value = "WELCOME sum is : "

Range("a3").Value = c

End Sub

Sub SI()

Dim P As Integer

Dim R As Double

Dim T As Integer

Dim Simp_Int As Double

P = 5000

R = 0.1
T=5

Simp_Int = P * R * T

Range("b2").Value = "Simple interest"

Range("b3").Value = Simp_Int

End Sub

Sub SI2()

Dim P As Integer

Dim R As Double

Dim T As Integer

Dim Simp_Int As Double

P = 5000

R = 0.1

T = 10

T = Application.InputBox("Enter a number")

Simp_Int = P * R * T

Range("b2").Value = "Simple interest"

Range("b3").Value = Simp_Int

End Sub

You might also like