VISUAL BASIC FOR APPLICATION
PRACTICAL EXERCISE
EXERCISE EXERCISE TITLE PAGE NO.
NO.
1 Familiarizations With The VBA Editor 1
2 Simple Program Involving VBA Data Type ,Variables 2
,Operator And Constants
3 Working with string Function in VBA 5
4 Creating and manipulating arrays in VBA 6
5 Working with string variable in VBA 8
6 Working with conditional statement 10
7 Working with looping statement 12
8 Working With Message box And Input box 15
9 Creating Function And Procedure 17
10 Creating And Editing macros 18
11 Working With Excel VBA Forms And Forms Controls 19
12 Using active X Controls 21
13 Simple Project Involving MS Excel And VBA 23
Project1. Creating A Calculator 23
Project2. Creating a Student Information Form 27
Project3 Creating A Loan Calculator 29
Project4. Equation Solving Program 31
Exersice1. Familiarizations With The VBA Editor
Object1.1- Starting a Microsoft Visual Basic
Procedure –
Step1. Click to Start Button And Click On Microsoft Excel
Step2. Click On Developer Tab And Click On Visual Basic
Step3. Click On Insert Option And Insert A User Form
Step4. Click on Excel Button And Return to Excel
Exersice No 2. Simple Program Involving VBA Data Type ,Variables ,Operator And
Constants
Object 2. 1.Working With VBA Data Type And Variable
Procedure –
Step1. Click To Insert And Insert A Form
Step2. Click To Tool box And Click To Command Button
Step3. Click And Drag And Drop To User Form
Step4. Double Click To Command Button and U See The Code Window
Step5. Write This Code And Run A Program
Working with byte variable
Private Sub CommandButton1_Click()
Dim Shirts As Byte
Dim Pants As Byte
Dim OtherItems As Byte
Dim TotalItems As Byte
Shirts = 6
Pants = 4
OtherItems = 2
TotalItems = Shirts + Pants + OtherItems
MsgBox ("1 Byte""0 to 255""Totalitems" & TotalItems)
End Sub
Working with variant variable
Private Sub CommandButton10_Click()
Dim FullName As Variant
Dim EmploymentStatus As Variant
Dim HourlySalary As Variant
Dim DateHired As Variant
FullName = "honeysen"
EmploymentStatus = 2
HourlySalary = 35.65
DateHired = #12/20/1994#
MsgBox ("fullname" & FullName)
MsgBox ("employmentstatus" & EmploymentStatus)
MsgBox ("hourlysalary" & HourlySalary)
MsgBox ("datehired" & DateHired)
End Sub
Working with Integer variable
Private Sub CommandButton2_Click()
Dim Tracks As Integer
Tracks = 100
MsgBox ("2Bytes""-32,768""32,767""Tracks" & Tracks)
End Sub
Working with long variable
Private Sub CommandButton3_Click()
Dim population As Long
population = 100
MsgBox ("4bytes""-2,147,483,648to2,147,483,647""population" & population)
End Sub
Working with single variable
Private Sub CommandButton4_Click()
Dim Distance As Single
Distance = 100
MsgBox ("4Byte""3.402823E38to3.402823E38""Distance" & Distance)
End Sub
Working with double variable
Private Sub CommandButton5_Click()
Dim Distance As Double
Distance = 100
MsgBox ("-1.79769313486232E308to1.79769313486232E308""Distance" & Distance)
End Sub
Working with string variable
Private Sub CommandButton6_Click()
Dim CustomerName As String
CustomerName = "vijay"
MsgBox ("10bytes+string length""0to2billion""customer name" & CustomerName)
End Sub
Working with currency variable
Private Sub CommandButton7_Click()
Dim startingsalary As Currency
startingsalary = 30000
MsgBox ("8bytes""-922,337,203,685,477,to922,337,203,685,477""Starting Salary" &
startingsalary)
End Sub
Working with date variable
Private Sub CommandButton8_Click()
Dim dateofbirth As Date
dateofbirth = #8/18/1998#
MsgBox ("8bytesjanuary1,100todecember31,9999""Date of Birth" & dateofbirth)
End Sub
Object2.2- Working With Logical Operator
Private Sub CommandButton1_Click()
Dim per As Single
per = TextBox1.Text
If per >= 60 Then
TextBox2.Text = "1st Div."
End If
If per >= 45 And per < 60 Then
TextBox2.Text = "2nd Div."
End If
If per >= 36 And per < 45 Then
TextBox2.Text = "3rd Div."
End If
If per < 36 Then
TextBox2.Text = "Fail"
End If
End Sub
Exercise No. 3 Working with string variable in VBA
Object3.1- Working with string fixed variable and variable length string Variable length string.
Private Sub CommandButton1_Click()
Dim nm As String
nm = "Mohit"
MsgBox nm
nm = "sunil kumar"
MsgBox nm
nm = "sun"
MsgBox nm
End Sub
Varable fixed length string
Private Sub CommandButton2_Click()
Dim nm As String * 5
nm = "Mohit"
MsgBox nm
nm = "sunil kumar"
MsgBox nm
nm = "sun"
MsgBox nm
End Sub
Exercise No.4 Creating and manipulating arrays in VBA
Object4.1 single dimensions arrays
private sub command button1_click()
Dim a (4) As integer
Dim I As integer, max As integer
For I = 0 to 4
a (i) = inputbox (“Enter a number.”)
Next
Max = a (0)
For I = 1 to 4
If a (i) > max Then
Max = a (i)
End if
Next
Msgbox “largest = “ & max
End sub
Object 4.2 double dimensions arrays
Private Sub cmdsum_Click()
Dim matrix1(1, 1) As Integer, matrix2(1, 1) As Integer
Dim sum(1, 1) As Integer
'initializiation of matrix1
matrix1(0, 0) = Val(Text1.Text)
matrix1(0, 1) = Val(Text2.Text)
matrix1(1, 0) = Val(Text3.Text)
matrix1(1, 1) = Val(Text4.Text)
'initializiation of matrix2
matrix2(0, 0) = Val(Text5.Text)
matrix2(0, 1) = Val(Text6.Text)
matrix2(1, 0) = Val(Text7.Text)
matrix2(1, 1) = Val(Text8.Text)
'summation of two matrices
For i = 0 To 1
For j = 0 To 1
sum(i, j) = matrix1(i, j) + matrix2(i, j)
Next j
Next i
'displaying the result
Debug.Print "The resultant matrix"
For i = 0 To 1
For j = 0 To 1
Debug.Print sum(i, j);
Next j
Debug.Print ""
Next i
End Sub
Exercise No. 5 Working with string functions
Object5.1 working with VBA string inbuilt function
Example 1 Lan(string)
Private Sub CommandButton1Click()
Dim a As String
a = lnputBox("Enter A Word")
MsgBox Len(a)
Example 2 LCase
a = lnputBox("Enter a Capital Word")
MsgBox LCase(a)
Example 3 ucase
a = lnputBox("Enter a Small Word')
MsgBox UCase(a)
Example 4 Left(string)
a = lnputBox("Enter a Word")
MsgBox Left(a, 4)
Example 5 right(string)
a = InputBox("Enter A word")
MsgBox Right(a, 5)
Example 6 Mid(string)
a = InputBox("Enter A Word")
MsgBox Mid(a, 4, 5)
Example 7 string
a = lnpuBox("Enter A Word")
MsgBox String(4, a)
Example 8 ASCII code
a = I nputBox(" Enter A ASCII Code")
MsgBox Asc(a)
Example 9 Str reverse
a = lnputBox("Enter a Name")
MsgBox StrReverse(a)
Example 1O Now() function
MsgBox Now()
Example 11 day function
a = lnputBox("enter a date")
MsgBox Day(a)
Exercise No 6 Working with conditional statement
Object 6.1- use of if- then- else- End if
Object1. Use of Nested if statement
Private Sub CommandButton1_Click()
Dim a%, b%, c%
TextBox4.Text = ""
a = TextBox1.Text
b = TextBox2.Text
c = TextBox3.Text
If a > b Then
If a > c Then
TextBox4.Text = a
Else
TextBox4.Text = c
End If
Else
If b > c Then
TextBox4.Text = b
Else
TextBox4.Text = c
End If
End If
End Sub
Object6.2. use of Iif statement
Private Sub CommandButton1_Click()
Dim a%, b%, c%
a = TextBox1.Text
b = TextBox2.Text
c = IIf(a > b, a, b)
TextBox3.Text = c
End Sub
Object 6.3- use of iif statement
Private Sub CommandButton1_Click()
Dim a%
a = TextBox1.Text
Select Case a
Case 1
TextBox2.Text = "One"
Case 2
TextBox2.Text = "Two"
Case 3
TextBox2.Text = "Three"
Case Else
TextBox2.Text = "Not Between 1 and 3"
End Select
End Sub
Object 6.4- use logical And Statement
Private Sub CommandButton1_Click()
Dim a%
a = TextBox1.Text
Select Case a
Case 1
TextBox2.Text = "One"
Case 2
TextBox2.Text = "Two"
Case 3
TextBox2.Text = "Three"
Case Else
TextBox2.Text = "Not Between 1 and 3"
End Select
End Sub
Exercise No-7 Working with looping statement
Object 7.1- use of while – wend loop
Private Sub CommandButton1_Click()
Dim a As Byte
a=1
While a <= 5
'Debug.Print "Hello"
'ActiveCell.FormulaR1C1 = "hello"
Cells(a, 1) = "hello"
a=a+1
Wend
End Sub
Object 7.2- use of Do –while loop
Private Sub CommandButton11_Click()
Dim a As Byte
a=1
Do While a <= 20
Cells(a, 1) = ""
a=a+1
Loop
End Sub
Object7.3- use of loop while
Private Sub CommandButton3_Click()
Dim a As Byte
a=1
Do
'Debug.Print a
Cells(a, 1) = a
a=a+1
Loop While a <= 5
End Sub
Object7.4- use of Do until loop
Private Sub CommandButton4_Click()
Dim a As Byte
a=1
Do Until a > 10
'Debug.Print a
Cells(a, 1) = a
a=a+1
Loop
End Sub
Object7.5- Do loop until
Private Sub CommandButton5_Click()
Dim a As Byte
a=1
Do
'Debug.Print a
Cells(a, 1) = a
a=a+1
Loop Until a > 10
End Sub
Object7.6- Use For Next Loop
Private Sub CommandButton6_Click()
Dim a As Byte
For a = 1 To 20
'Debug.Print a
Cells(a, 1) = a
Next a
End Sub
Object7.7- use Of Exit Do ,Exit For, Exit Sub, Go To Exit Do
Private Sub CommandButton7_Click()
Dim c%
c=1
Do While c <= 5
'Debug.Print c
Cells(c, 1) = c
If c = 3 Then Exit Do
c=c+1
Loop
End Sub
Use of Exit For
Private Sub CommandButton8_Click()
Dim c%
For c = 1 To 5
'Debug.Print c
Cells(c, 1) = c
If c = 3 Then Exit For
Next
End Sub
Exit Sub
Private Sub CommandButton9_Click()
'Debug.Print "A"
Cells(1, 1) = "A"
'Debug.Print "B"
Cells(2, 1) = "B"
Exit Sub
'Debug.Print "C"
Cells(3, 1) = "c"
'Debug.Print "D"
Cells(4, 1) = "d"
'Debug.Print "E"
Cells(5, 1) = "e"
End Sub
Go To statement
Private Sub CommandButton10_Click()
Dim a%
For a = 1 To 10
'Debug.Print a
Cells(a, 1) = a
If a = 5 Then
GoTo out
End If
Next
out:
End Sub
Exersice No.8 Working With Message box And Input box
Object8.1 – Use of Input box
Private Sub CommandButton1_Click()
Dim a As String
a = InputBox("Enter A Name")
MsgBox (a)
End Sub
Object8.2- Use of msg box
Private Sub CommandButton1_Click()
MsgBox "My Prompt", vbOKOnly, "My Title"
End Sub
Private Sub CommandButton10_Click()
MsgBox "My Prompt", vbInformtion, "My Title"
End Sub
Private Sub CommandButton11_Click()
End Sub
Private Sub CommandButton2_Click()
MsgBox "My Prompt", vbOKCancel, "My Title"
End Sub
Private Sub CommandButton3_Click()
MsgBox "My Prompt", vbAbortRetryIgnore, "My Title"
End Sub
Private Sub CommandButton4_Click()
MsgBox "My Prompt", vbYesNoCancel, "My Title"
End Sub
Private Sub CommandButton5_Click()
MsgBox "My Prompt", vbYesNo, "My Title"
End Sub
Private Sub CommandButton6_Click()
MsgBox "My Prompt", vbRetryCancel, "My Title"
End Sub
Private Sub CommandButton7_Click()
MsgBox "My Prompt", vbQuestion, "My Title"
End Sub
Private Sub CommandButton8_Click()
MsgBox "My Prompt", vbCritical, "My Title"
End Sub
Private Sub CommandButton9_Click()
MsgBox "My Prompt", vbExclamation, "My Title"
End Sub
Exesice No.9 Creating Function And Procedure
Object9.1- Creating Function
Function Addtwo(X, Y)A
Addtwo = X + Y
End Function
Function Subtwo(X, Y)
Subtwo = X - Y
End Function
Object9.2- Creating a Procedure
Sub Area(x As Double, y As Double)
MsgBox x * y
End Sub
Exesice No10. Creating And Editing macros
Object10.1- Creating And Run Macros
Exercise working with macros
Object. Create a macros for formatting (own formatting)
start microsoft excel
click the developer tab
click to record macros
enter macro name format click on ok.
Place cell pointer at A1
Click to home tab
Set a fill color
Set a font –Algerian
Set font size -16
Set style-BOLD
Click on developer tab
Click on stop recording
Create button for macro
Click on insert and click shape
Choose a shape and Drag and Drop at specification cell
Right click on create shape and click on assign macros
Choose a macros name and click on OK
Give name to shape own formetting by right click on shape and click on edit text then
type own formetting .
Click on macro link button for Run a macros
Exersice No.11. Working With Excel VBA Forms And Forms Controls
UserForm Controls ToolBox
UserForm ToolBox Controls
Control Use
Stores text which is not editable by user, and is used to describe other
Label
controls.
TextBox Holds text by allowing user to enter or modify.
Is a list of items from which a user can select, and also allows user to enter his
ComboBox
own item in the text box. ComboBox is a combination of TextBox and ListBox.
Is a list of items from which a user can select, but does not allow user to enter
ListBox
his own item.
A CheckBox whether selected or not, indicates True or False values. Used to
CheckBox
select mutually exclusive options viz. Yes/No, On/Off, …
Used to make one selection from multiple options. Also referred to as Radio
OptionButton
Button.
Executes one action when clicked first and a different action on the second
ToggleButton
click. The button toggles bewteen the two states, On and Off.
Used to group controls that work together or have some commonality.
Frame Particularly useful to group OptionButtons which become mutually exclusive
within a Frame.
CommandButton A button, when clicked by the user, executes a code or action.
Is a collection of Tabs wherein each Tab contains the same set of controls, and
TabStrip
the content of the controls changes when a different Tab is selected.
Comprises of one or more Page objects, each containing its own set of
MultiPage controls. Selecting a Page (ie. making it visible) hides the other Pages of the
MultiPage control.
Is used to change (increment or decrement) the value displayed by other
ScrollBar controls. The ScrollBar box can be dragged to change the control's value over
larger increments.
Similar to a ScrollBar, is used to increment or decrement the value displayed
SpinButton
by other controls, without the drag facility.
Image Is used to display a Picture on the UserForm.
Allows a user to select a worksheet range from a box, or to type in the range
RefEdit
therein. It behaves similar to the built-in Excel reference boxes.
UserForm Basics
UserForm
VBA Code What is Does
Application
Displays the UserForm with name UserForm1. This
code should be inserted in a Standard VBA Module
To Display a and not in the Code Module of the UserForm. You
UserForm1.Show
UserForm can create a button in a worksheet, then right click
to assign macro to this button, and select the macro
which shows the UserForm.
Load statement is useful in case of a complex
Load a
UserForm that you want to load into memory so
UserForm into
Load UserForm1 that it displays quickly on using the Show method,
memory but do
which otherwise might take a longer time to
not display
appear.
Remove a Note: The Hide method (UserForm1.Hide) does not
UserForm from unload the UserForm from memory. To unload the
Unload UserForm1
memory / Close UserForm from memory, the Unload method should
UserForm be used.
Use the Me keyword in a procedure in the Code
Unload Me
Module of the UserForm.
Using the Hide method will temporarily hide the
Hide a
UserForm1.Hide UserForm, but will not close it and it will remain
UserForm
loaded in memory.
Print a The PrintForm method sends the UserForm directly
UserForm1.PrintForm
UserForm for printing.
If the UserForm is displayed as Modeless, user can
continue working in Excel while the UserForm
Display continues to be shown. Omitting the Boolean
UserForm as UserForm1.Show False argument (False or 0) will display the UserForm as
Modeless Modal, in which case user cannot simultaneously
work in Excel. By default UserForm is displayed as
Modal.
Close a
Unload UserForm1 The Unload method closes the specified UserForm.
UserForm
The Unload method closes the UserForm within
Unload Me
whose Code Module it resides.
Use the End statement in the "Close"
End CommandButton to close the form. The "End"
statement unloads all forms.
Specify Caption is the text which describes and identifies a
UserForm1.Caption
UserForm UserForm and will display in the header of the
= "Bio Data"
Caption Userform.
Set UserForm UserForm1.Height =
Set Height of the UserForm, in points.
Size 350
UserForm1.Width =
Set Width of the UserForm, in points.
550
Set UserForm
Position:
Left & Top Distance set is between the form and the Left or
UserForm1.Left = 30
properties Top edge of the window that contains it, in pixels.
UserForm1.Top = 50
Move method includes two arguments which are
UserForm1.Move 200,
Move method required - the Left distance and the Top distance, in
50
that order.
Exersice No12. Useing active X Controls
Create ActiveX controls such as command buttons, text boxes, list boxes etc. To create an
ActiveX control in Excel VBA, execute the following steps.
1. On the Developer tab, click Insert.
2. For example, in the ActiveX Controls group, click Command Button to insert a command
button control.
3. Drag a command button on your worksheet.
4. Right click the command button (make sure Design Mode is selected).
5. Click View Code.
Note: you can change the caption and name of a control by right clicking on the control (make
sure Design Mode is selected) and then clicking on Properties. Change the caption of the
command button to 'Apply Blue Text Color'. For now, we will leave CommandButton1 as the
name of the command button.
The Visual Basic Editor appears.
6. Add the code line shown below between Private Sub CommandButton1_Click() and End Sub.
7. Select the range B2:B4 and click the command button (make sure Design Mode is
deselected).
Result:
Exersice No13. Simple Project Involing MS Excel And VBA
Object. Creating A Calculator
Dim sign As String
Dim val1 As Double
Dim val2 As Double
Private Sub cmd0_Click()
txtbox.Value = txtbox.Value & cmd0.Caption
End Sub
Private Sub cmd1_Click()
txtbox.Value = txtbox.Value & cmd1.Caption
End Sub
Private Sub cmd2_Click()
txtbox.Value = txtbox.Value & cmd2.Caption
End Sub
Private Sub cmd3_Click()
txtbox.Value = txtbox.Value & cmd3.Caption
End Sub
Private Sub cmd4_Click()
txtbox.Value = txtbox.Value & cmd4.Caption
End Sub
Private Sub cmd5_Click()
txtbox.Value = txtbox.Value & cmd5.Caption
End Sub
Private Sub cmd6_Click()
txtbox.Value = txtbox.Value & cmd6.Caption
End Sub
Private Sub cmd7_Click()
txtbox.Value = txtbox.Value & cmd7.Caption
End Sub
Private Sub cmd8_Click()
txtbox.Value = txtbox.Value & cmd8.Caption
End Sub
Private Sub cmd9_Click()
txtbox.Value = txtbox.Value & cmd9.Caption
End Sub
Private Sub cmdclear_Click()
txtbox.Text = ""
val1 = 0
val2 = 0
sign = ""
End Sub
Private Sub cmdcos_Click()
Dim v As Double
On Error GoTo aa
v = CDbl(txtbox.Value)
txtbox.Value = Math.Cos(v)
aa: Exit Sub
End Sub
Private Sub cmddivide_Click()
sign = "/"
On Error GoTo aa
val1 = CDbl(txtbox.Value)
txtbox.Value = ""
aa: Exit Sub
End Sub
Private Sub cmdequal_Click()
On Error GoTo aa
val2 = CDbl(txtbox.Value)
If (sign = "+") Then
txtbox.Text = val1 + val2
ElseIf (sign = "-") Then
txtbox.Text = val1 - val2
ElseIf (sign = "*") Then
txtbox.Text = val1 * val2
Else: txtbox.Text = val1 / val2
End If
aa: Exit Sub
End Sub
Private Sub cmdmultiply_Click()
sign = "*"
On Error GoTo aa
val1 = CDbl(txtbox.Value)
txtbox.Value = ""
aa: Exit Sub
End Sub
Private Sub cmdplus_Click()
sign = "+"
On Error GoTo aa
val1 = CDbl(txtbox.Value)
txtbox.Value = ""
aa: Exit Sub
End Sub
Private Sub cmdsin_Click()
Dim v As Double
On Error GoTo aa
v = CDbl(txtbox.Value)
txtbox.Value = Math.Sin(v)
aa: Exit Sub
End Sub
Private Sub cmdsqare_Click()
Dim v As Double
On Error GoTo aa
v = CDbl(txtbox.Value)
txtbox.Value = v ^ 2
aa: Exit Sub
End Sub
Private Sub cmdsqrt_Click()
Dim v As Double
On Error GoTo aa
v = CDbl(txtbox.Value)
txtbox.Value = Math.Sqr(v)
aa: Exit Sub
End Sub
Private Sub cmdsubtract_Click()
sign = "-"
On Error GoTo aa
val1 = CDbl(txtbox.Value)
txtbox.Value = ""
aa: Exit Sub
End Sub
Private Sub cmdtan_Click()
Dim v As Double
On Error GoTo aa
v = CDbl(txtbox.Value)
txtbox.Value = Math.Tan(v)
aa: Exit Sub
End Sub
Private Sub txtbox_Change()
End Sub
Private Sub txtbox_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If (KeyAscii >= vbKey0 And KeyAscii <= vbKey9) Or (Chr(KeyAscii) = ".") Then
Exit Sub
Else: KeyAscii = vbKeyBack
End If
End Sub
Private Sub UserForm_Click()
End Sub
Project 3. Creating a Student Information Form
Dim c As Integer
Dim t As Integer
Private Sub CommandButton1_Click()
txtid.Text = ""
txtname.Text = ""
txtsex.Text = ""
txtdob.Text = ""
txtpob.Text = ""
txtphone.Text = ""
End Sub
Private Sub CommandButton2_Click()
Call setval(c)
c=c+1
Workbooks("exercise_VBA.xlsm").Save
End Sub
Private Sub CommandButton3_Click()
For i = 1 To c
If Cells(i, 1) = txtid.Text Then
Rows(i).Delete
c=c-1
Workbooks("exercise_VBA.xlsm").Save
End If
Next
End Sub
Private Sub CommandButton4_Click()
For i = 1 To c
If Cells(i, 1) = txtid.Text Then
Call setval(i)
Workbooks("exercise_VBA.xlsm").Save
End If
Next
End Sub
Private Sub CommandButton5_Click()
If t >= 3 Then
t=t-1
Call MoveRow(t)
End If
End Sub
Private Sub CommandButton6_Click()
If t < c Then
Call MoveRow(t)
t=t+1
End If
End Sub
Private Sub UserForm_Initialize()
Rows("1:100").Select
c=1
t=2
Call MoveRow(t)
While Cells(c, 1) <> ""
c=c+1
Wend
End Sub
Sub MoveRow(t As Integer)
txtid.Text = Cells(t, 1)
txtname.Text = Cells(t, 2)
txtsex.Text = Cells(t, 3)
txtdob.Text = Cells(t, 4)
txtpob.Text = Cells(t, 5)
txtphone.Text = Cells(t, 6)
End Sub
Sub setval(ByVal i As Integer)
Cells(i, 1) = txtid.Text
Cells(i, 2) = txtname.Text
Cells(i, 3) = txtsex.Text
Cells(i, 4) = txtdob.Text
Cells(i, 5) = txtpob.Text
Cells(i, 6) = txtphone.Text
End Sub
Project3. Creating A Loan Calculator
Option Explicit
Sub Calculate()
Dim loan As Long, rate As Double, nper As Integer
loan = Range("D4").Value
rate = Range("F6").Value
nper = Range("F8").Value
If Sheet1.OptionButton1.Value = True Then
rate = rate / 12
nper = nper * 12
End If
Range("D12").Value = -1 * WorksheetFunction.Pmt(rate, nper, loan)
End Sub
Project4. Equation Solving Program
Code
Private Sub Solve_Click()
Dim a, b, c, d, m, n As Integer
Dim x, y As Double
a = Val(Txt_a.Text)
b = Val(Txt_b.Text)
m = Val(Txt_m.Text)
c = Val(Txt_c.Text)
d = Val(Txt_d.Text)
n = Val(Txt_n.Text)
x = (b * n - d * m) / (b * c - a * d)
y = (a * n - c * m) / (a * d - b * c)
Lbl_x.Caption = Round(x, 2)
Lbl_y.Caption = Round(y, 2)
End Sub
'to get new equations
Private Sub Cmdnew_Click()
Txt_a.Text = ""
Txt_b.Text = ""
Txt_m.Text = ""
Txt_c.Text = ""
Txt_d.Text = ""
Txt_n.Text = ""
Lbl_x.Caption = ""
Lbl_y.Caption = ""
End Sub
Private Sub UserForm_Click()
BackColor = vbBlue
ForeColor = vbGreen
End Sub