Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Vba Litho.

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 28

Visual Basic Application

Visual Basic Application


Created By:-Bhagavatee Dharaviya
Batch No:-Copa –B-77
Roll No.:-74

S.I. (M.V.Khetiya
Contents
Demo no. 68: Familiarization with VBA editor(week no.-30)...............................................................4
Demo no. 69: Use Form Controls in Excel VBA(Week no.-30)............................................................5

Page No. 1
Visual Basic Application
1. Button:..........................................................................................................................................6
2. Combo-Box & List-Box:.................................................................................................................6
3. Check Box & Radio Button:...........................................................................................................7
4. Spin Button & Scroll Bar:...............................................................................................................7
5.From Controls.................................................................................................................................9
Demo-70 Basic Programming in VBA(Weekno.-31)..........................................................................10
1-Print..............................................................................................................................................10
2-Variable Constant Data type.........................................................................................................11
3-Arithmetic Operators....................................................................................................................13
4-Concatenation...............................................................................................................................14
5-Comparison Operators..................................................................................................................15
6-Logical Operators.........................................................................................................................17
Demo-71 Dialog oxes in VBA(Week no.-31)......................................................................................19
1-MSG Box.....................................................................................................................................19
2-Input Box......................................................................................................................................21
Demo-72 Conditional Statements in VBA(Weekno.-31).....................................................................22
Demo-73 Loops in VBA(Weekno.-32)................................................................................................26

Page No. 2
Visual Basic Application

Page No. 3
Visual Basic Application

Demo no. 68: Familiarization with VBA editor (week


no.-30)
 For using VBA first of all open Developer tab in Excel.
 If Developer tab in not visible then to add it click on “File” menu “Option” in
MS Excel 2010 and 2013.
 Dialogbox named “Excel options” will open. In which on the left side click on
“Customize ribbon”. On the right side you will see the options of “Customize ribbon”.
Here, check the box of “Developer” inside “Main tabs” and click on “ok” button.
Developer ribbon will be added in Excel.

Open VBA Editor Run or Record Macro ActiveX or Form Modify Controls
Controls Properties
 There are various methods to open VBA editor. Which is as following.
 Click on “Visual Basic” button in the “code” panel of “Developer” tab.
 Click on “View code” button in the “Controls” panel of “Developer” tab.
 By pressing Alt + F11 shortcut key.

Page No. 4
Visual Basic Application
Menu Bar Tool Bar

Project Explorer Window Code Window

Stared on: - 24/02/2020


Completed on:-24/02/2020

X
S.I. (M.V. Khetiya)

Page No. 5
Visual Basic Application

Demo no. 69: Use Form Controls in Excel VBA


(Week no.-30)

1. Button:

 First take a button of “Form controls” from “Insert” in “controls” panel of “Developer”
tab.
 Window of “Assign Macro” will open. Which is as below

 Then write a code in on click event.

2. Combo-Box & List-Box:


 Take a Combo-box/List-box of “Form controls” from “Insert” in “controls” panel of
“Developer” tab.

 Then right click on combo-box/list-box and click on “Format control”.

Page No. 6
Visual Basic Application
 Click in “control” tab inside “Format control” window.

 In input range select the range where you want to print answer.
 In the cell link select a cell you want to link.
 Then click on “ok” button.

3. Check Box & Radio Button:


 Take Check boxes/radio buttons of “Form controls” as per your need from “Insert” in
“Controls” panel of “Developer” tab.
 In “control” tab inside “Format control” window, select a cell for “cell link”.
 Then click on “ok” button.

4. Spin Button & Scroll Bar:


 Take spin button/scroll bar of “Form controls” from “Insert” in “Controls” panel of
“Developer” tab.
 Then open the format control window by right clicking on it.

 In the “controls” tab set values.


 Current value means the current value of scrollbar/spin button.
 Minimum/maximum value means the minimum/maximum value upto which a
scroll bar can be scrolled.

Page No. 7
Visual Basic Application
 Incremental change means the number of scroll you want to scroll at a time.
 After setting all these values click on “ok” button.

Page No. 8
Visual Basic Application

5.From Controls

Write a program in VBA to demonstrate how to use form control in worksheet.

Output:-

Stared on: - 25/02/2020


Completed on:-26/02/2020

X
S.I. (M.V. Khetiya)

Page No. 9
Visual Basic Application

Demo-70 Basic Programming in VBA(Weekno.-31)


1-Print
Write a program in VBA to demonstrate how to print value in cell of
worksheet.

Input:-
Private Sub CommandButton1_Click()
MsgBox ("Dharaviya Bhagavatee")
End Sub
Private Sub CommandButton2_Click()
Range("b1").Value = "Hello"
Range("c1:c10").Value = "Bhagavatee"
End Sub
Private Sub CommandButton3_Click()
Cells(11, 1) = "Copa-B-77"
ActiveCell.Value = "Apple"
End Sub

Output:-

Page No. 10
Visual Basic Application

2-Variable Constant Data type


Write a program in VBA to demonstrate the use of Data type, Variable &
Constant.

Input:-
Private Sub CommandButton1_Click()
Dim byte_no As Byte
byte_no = 25
Range("c5") = "byte datatype"
Range("d5") = byte_no

Dim integer_no As Integer


integer_no = 2000
Range("c7") = "integer datatype"
Range("d7") = integer_no

Dim long_no As Long


long_no = 20000
Range("c9") = "long datattype"
Range("d9") = long_no

Dim single_no As Single


single_no = 3509
Range("c11") = "single datatype"
Range("d11") = single_no

Dim double_no As Double


double_no = 25.19972
Range("c13") = "double datatype"
Range("d13") = double_no

Dim currency_no As Currency


currency_no = 86000
Range("c15") = "currency datatype"
Range("d15") = currency_no

Page No. 11
Visual Basic Application
Dim myname As String
myname = "Mahila Iti"
Range("h5") = "string"
Range("i5") = myname

Const name = "Mahila Iti"


Range("h7") = "constant"
Range("i7") = name

Dim boolean_value As Boolean


boolean_value = True
Range("h9") = "boolean"
Range("i9") = boolean_value

End Sub
Output:-

3-Arithmetic Operators
Write a program in VBA to demonstrate the use of Arithmetic Operators in
VBA. Page No. 12
Visual Basic Application

Input:-
Private Sub CommandButton1_Click()
Range("l4") = Range("j4") + Range("k4")
Range("l5") = Range("j5") - Range("k5")
Range("l6") = Range("j6") * Range("k6")
Range("l7") = Range("j7") / Range("k7")
Range("l8") = Range("j8") Mod Range("k8")
End Sub
Output:-

4-Concatenation
Write a program in VBA to demonstrate the use of Concatenation Operators
of VBA.
Page No. 13
Visual Basic Application

Input:-
Private Sub CommandButton1_Click()
Range("c2") = Range("a2") + Range("b2")
Range("c3") = Range("a3") + Range("b3")
Range("d2") = Range("a2") & Range("b2")
Range("d3") = Range("a3") & Range("b3")
End Sub

Output:-

5-Comparison Operators

Write a program in VBA to demonstrate the use of Comparison Operators


of VBA.
Page No. 14
Visual Basic Application

Input:-
Private Sub CommandButton1_Click()
If Range("E6") = Range("F6") Then
Range("G6").Value = "It's Equal to."
Else
Range("G6").Value = "It's not Equal to."
End If
If Range("E7") < Range("F7") Then
Range("G7").Value = "It's Equal to."
Else
Range("G7").Value = "It's not Equal to."
End If
If Range("E8") > Range("F8") Then
Range("G8").Value = "It's Equal to."
Else
Range("G8").Value = "It's not Equal to."
End If
If Range("E9") <= Range("F9") Then
Range("G9").Value = "It's Equal to."
Else
Range("G9").Value = "It's not Equal to."
End If
If Range("E10") >= Range("F10") Then
Range("G10").Value = "It's Equal to."
Else
Range("G10").Value = "It's not Equal to."
End If
If Range("E11") <> Range("F6") Then
Range("G11").Value = "It's Equal to."
Else
Range("G11").Value = "It's not Equal to."
End If
End Sub

Page No. 15
Visual Basic Application
Output:-

6-Logical Operators
Write a program in VBA to demonstrate the use of Logical Operators of
VBA.

Page No. 16
Visual Basic Application
Input:-
Private Sub CommandButton1_Click()
Dim Age1 As Integer
Age1 = 22
If Age1 < 13 And Age > 19 Then
Range("H7") = "Age is Between"
Else
Range("H7") = "Age is not Between"
End If
End Sub
Private Sub CommandButton2_Click()
Dim Age1 As Integer
Age1 = 22
If Age1 < 13 Or Age > 19 Then
Range("H8") = "Age is Between"
Else
Range("H8") = "Age is not Between"
End If
End Sub
Private Sub CommandButton3_Click()
Dim Age1 As Integer
Age1 = 22
If Not Age1 < 13 Then
Range("H9") = "Age is Between"
Else
Range("H9") = "Age is not Between"
End If
End Sub

Page No. 17
Visual Basic Application
Output:-

Stared on: - 27/02/2020


Completed on:-29/02/2020

X
S.I. (M.V.Khetiya)

Page No. 18
Visual Basic Application

Demo-71 Dialog Boxes in VBA(Week no.-31)


1-MSG Box
Write a program in VBA to demonstrate the use of msg box function & its
options.
Input:-
Private Sub CommandButton1_Click()
no = MsgBox("This is simple MSG Box.")
End Sub
Private Sub CommandButton2_Click()
no = MsgBox("This MSG Box is OK & Cancle.", vbOKCancel)
End Sub

Private Sub CommandButton3_Click()


no = MsgBox("This MSG Box is Yes & No.", vbYesNo)
End Sub
Private Sub CommandButton4_Click()
no = MsgBox("This MSG Box is Symbol.", vbExclamation + vbOKCancel)
End Sub

Private Sub CommandButton5_Click()


no = MsgBox("This MSG BOx is Title.", vbQuestion + vbYesNo, "Do You Save This File?")
End Sub
Private Sub CommandButton6_Click()
no = MsgBox("This MSG BOx is New Line" & vbNewLine &

End Sub
Private Sub CommandButton7_Click()
no = MsgBox("This MSG BOx is New Line" & vbNewLine & "Bhagavati Dharviya",
vbQuestion + vbYesNo, "Do You Save This File?")
End Sub

Page No. 19
Visual Basic Application
Output:-

Page No. 20
Visual Basic Application

2-Input Box
Write a program in VBA to demonstrate the use of Input box function & its
options.

Input:-
Private Sub CommandButton1_Click()
Dim a As String
a = InputBox("Plese Enter Your Name:", "Name Box", "Enter Your Name", 1000)
ActiveCell = a

End Sub
Output:-

Stared on: - 02/03/2020


Completed on:-02/03/2020

X
S.I. (M.V. Khetiya)

Page No. 21
Visual Basic Application

Demo-72 Conditional Statements in VBA(Weekno.-


31)
Write a program in VBA to demonstrate the use of all types of Conditional
Statements used in VBA.

Input:-
Private Sub CommandButton1_Click()
Dim a As Integer
a = Range("i4")
If a = 20 Then
Range("i5") = "Number is 20."
End If
End Sub

Private Sub CommandButton2_Click()


Dim a1 As Integer
Dim a2 As Integer
a1 = Range("i9")
a2 = Range("i10")
If a1 > a2 Then
Range("i11") = "Number 1 is Greater Then to NUmber2."
Else
Range("i11") = "Number 2 is Greater Then to NUmber1. "
End If

Page No. 22
Visual Basic Application
End Sub

Private Sub CommandButton3_Click()


Dim B As Integer
Dim h As Integer
B = Range("i15")
h = Range("i16")
If B > h Then
Range("i17") = "Number-1 Greater then to Number-2."
ElseIf h > B Then
Range("i17") = "Number-2 Greater then to Number-2."
Else
Range("i17") = "Number-1 is equal to Number-2."
End If
End Sub

Private Sub CommandButton4_Click()


Dim B As String
Dim a As Integer
B = Range("i20")
a = Range("i21")
If B = "Pass" Then
If a >= 30 And a < 40 Then
Range("i22") = "Your Gread is F."
ElseIf a >= 40 And a < 50 Then

Page No. 23
Visual Basic Application
Range("i22") = "Your Gread is E. "
ElseIf a >= 50 And a < 60 Then
Range("i22") = "Your Gread is D. "
ElseIf a >= 60 And a < 70 Then
Range("i22") = "Your Gread is C. "
ElseIf a >= 70 And a < 80 Then
Range("i22") = "Your Gread is B. "
Else
Range("i22") = "Your Gread is A . "
End If
Else
Range("i22") = "You Are Fail."
End If
End Sub

Private Sub CommandButton5_Click()

Dim Per As Integer


Dim Result As String
Per = Range("i26")
Select Case Per
Case Is >= 80
Result = "Very Good"
Case Is >= 70
Result = "Good"
Case Is >= 60
Result = "fine"
Case Is >= 50
Result = "sufficient"
Case Else
Result = "Insufficient"
End Select

Page No. 24
Visual Basic Application
Range("i28") = Result
End Sub

Private Sub CommandButton6_Click()


Dim X As Integer
Dim Y As Integer
X = Range("i32")
Y = Range("i33")
Select Case X = Y
Case True
Range("i34") = "Expression With True"
Case False
Range("i34") = "Expression With False"
End Select
End Sub

Stared on: - 03/03/2020


Completed on:-04/03/2020

X
S.I. (M.V. Khetiya)

Page No. 25
Visual Basic Application

Demo-73 Loops in VBA(Weekno.-32)


Write a program in VBA to demonstrate the use of all types of looping
Statements used in VBA.

Input:-
Private Sub CommandButton1_Click()
Dim a As Integer
Dim r As Integer
a = Range("c3")
r=4
For i = a To 0 Step -2
Cells(r, 3) = i
r=r+1
Next

End Sub
Private Sub CommandButton2_Click()
Z=1
flower = Array("Sunflower", "Rose", "Chamali")
Dim flowersname As Variant
For Each Item In flower
flowersname = flowersname & Item & Chr(10)
Cells(12, Z) = flowersname
Z=Z+1
Next
End Sub

Page No. 26
Visual Basic Application
Private Sub CommandButton3_Click()
a=1
Do While B < 5
B=B+1
Cells(16, B) = B
Loop
End Sub

Private Sub CommandButton4_Click()


a=1
c = 10
Do
c=c+1
Cells(22, a) = c
a=a+1
Loop While c < 15
End Sub

Private Sub CommandButton5_Click()


X=1
B = 10
Do Until B > 15
B=B+1
Cells(29, X) = B
X=X+1
Loop
End Sub

Page No. 27
Visual Basic Application

Private Sub CommandButton6_Click()


B=2
Z = 15
Do
Z=Z+1
B=B+1
Cells(39, B) = Z
Loop Until B < 20
End Sub

Stared on: - 05/03/2020


Completed on:-07/03/2020

X
S.I. (M.V.Khetiya)

Page No. 28

You might also like