16
1 Table of Contents Introduction ............................................................................................................. ................... 2 visual basic for excel ....................... ....................................................................................... 2 Control str ucture to develop user defined functions ..............................................................3 Discussion of system..................................................................................................................4 Conclusion .............................................................................................................. ................. 15 References ................................................................................................................................ 16

Csc 248 Assignment 2 Documentation

Embed Size (px)

Citation preview

Page 1: Csc 248 Assignment 2 Documentation

7/29/2019 Csc 248 Assignment 2 Documentation

http://slidepdf.com/reader/full/csc-248-assignment-2-documentation 1/16

1

Table of Contents

Introduction ................................................................................................................................ 2

visual basic for excel .............................................................................................................. 2

Control structure to develop user defined functions .............................................................. 3

Discussion of system.................................................................................................................. 4

Conclusion ............................................................................................................................... 15

References ................................................................................................................................ 16

Page 2: Csc 248 Assignment 2 Documentation

7/29/2019 Csc 248 Assignment 2 Documentation

http://slidepdf.com/reader/full/csc-248-assignment-2-documentation 2/16

2

Introduction

visual basic for excel 

Visual Basic for Applications (VBA) is an implementation of Microsoft's event-driven

 programming language, visual basic 6 and its associated integrated development environment

which are built into most Microsoft Office applications. VBA enables building user defined

functions, automating processes and accessing Windows API and other low-level

functionality through dynamic libraries (DLLs). It can be used to control many aspects of the

host application, including manipulating user interface features, such as menus and toolbars,

and working with custom user forms or dialog boxes. As its name suggests, VBA is closely

related to Visual Basic and uses the Visual Basic Runtime Library, but can normally only run

code within a host application rather than as a standalone program. It can, however, be used

to control one application from another via OLE automation. For example, it is used to

automatically create a Word report from Excel data, which is in turn automatically collected

 by Excel from polled observation sensors. (Visual Basic for Applications, 2012)

VBA macros can be created with malicious intent. Using VBA, most of the security features

lie in the hands of the user, not the author. The VBA host application options are accessible

to the user. The user who runs any document containing VBA macros can preset the software

with user preferences. End-users can protect themselves from attack by disabling macros

from running in an application, or only grant permission for a document to run VBA code if 

they are sure the source of the document can be trusted. (Visual Basic for Applications, 2012)

If a user is looking for an easier way to perform a mundane, repetitive task, or to perform

some task that the UI does not seem to address. Then, Office applications like Excel have

Visual Basic for Applications (VBA), a programming language that gives you the ability to

extend those applications.

VBA works by running macros, step-by-step procedures written in Visual Basic. Learning to

 program might seem intimidating, but with some patience, many users find that learning even

a small amount of VBA code makes their work easier and gives them the ability to do things

Page 3: Csc 248 Assignment 2 Documentation

7/29/2019 Csc 248 Assignment 2 Documentation

http://slidepdf.com/reader/full/csc-248-assignment-2-documentation 3/16

3

in Office that they did not think were possible. Once you have learned some VBA, it becomes

much easier to learn a whole lot more. So the possibilities here are limitless.

By far the most common reason to use VBA in Excel is to automate repetitive tasks. For 

example, suppose that you have a few dozen workbooks, each of which has a few dozen

worksheets, and each of those needs to have some changes made to it. The changes could be

as simple as applying new formatting to some fixed range of cells or as complex as looking at

some statistical characteristics of the data on each sheet, choosing the best type of chart to

display data with those characteristics, and then creating and formatting the chart

accordingly. Either way, you would probably rather not have to perform those tasks

manually, at least not more than a few times. Instead, you could automate the tasks by using

VBA to write explicit instructions for Excel to follow.

VBA is not just for repetitive tasks though. You can also use VBA to build new capabilities

into Excel (for example, you could develop new algorithms to analyze your data, then use the

charting capabilities in Excel to display the results), and to perform tasks that integrate Excel

with other Office applications such as Microsoft Access 2010. In fact, of all the Office

applications, Excel is the one most used as something that resembles a general development

 platform. In addition to all the obvious tasks that involve lists and accounting, developers use

Excel in a range of tasks from data visualization to software prototyping. (Chinowsky, 2009)

Control structure to develop user defined functions

To develop user defined functions the user would need to go to the developer tab on the

ribbon then click on visual basics in the macros section. Once there, the user creates a new

module and types their desired function. Once done the user clicks run and the action is

displayed.

Page 4: Csc 248 Assignment 2 Documentation

7/29/2019 Csc 248 Assignment 2 Documentation

http://slidepdf.com/reader/full/csc-248-assignment-2-documentation 4/16

4

Discussion of system

The system I created consists of 5 worksheets and 5 user defined functions and procedures.

The below image shows the first worksheet which is linked to the second worksheet. It is a

record of the company's overall sales and the second sheet is the company's daily sales. I

created a function to get the daily figures on the second sheet into the first sheet using a user 

defined function in the form of a button. The button is labelled Transfer Daily sales data.

Page 5: Csc 248 Assignment 2 Documentation

7/29/2019 Csc 248 Assignment 2 Documentation

http://slidepdf.com/reader/full/csc-248-assignment-2-documentation 5/16

5

Page 6: Csc 248 Assignment 2 Documentation

7/29/2019 Csc 248 Assignment 2 Documentation

http://slidepdf.com/reader/full/csc-248-assignment-2-documentation 6/16

6

Once the Transfer Daily sales data button is clicked, the daily data is sent to the overall sales

sheet and a dialog box is shown with the words data transfer successful.

If there is a missing date, a dialog box would show up saying "the data you are trying to

transfer is not of today's date do you still wish to transfer?" with a yes ,no and cancel option.

Clicking yes brings up the same data transfer successful box and clicking no brings up a box

that says find current data and run again. 

Page 7: Csc 248 Assignment 2 Documentation

7/29/2019 Csc 248 Assignment 2 Documentation

http://slidepdf.com/reader/full/csc-248-assignment-2-documentation 7/16

7

Page 8: Csc 248 Assignment 2 Documentation

7/29/2019 Csc 248 Assignment 2 Documentation

http://slidepdf.com/reader/full/csc-248-assignment-2-documentation 8/16

8

Page 9: Csc 248 Assignment 2 Documentation

7/29/2019 Csc 248 Assignment 2 Documentation

http://slidepdf.com/reader/full/csc-248-assignment-2-documentation 9/16

9

The next sheet consists of two functions, the first being the count once function. This

function takes a list and counts all the number of entries without counting repeated entries. As

shown in the image there are 9 names but only 7 were counted as 2 were repeated. Also in the

next sheet is a recorded user defined function that sorts the data in cell A alphabetically and

highlights figure in cell B. This function is activated by the click of the "sort data" button.

Page 10: Csc 248 Assignment 2 Documentation

7/29/2019 Csc 248 Assignment 2 Documentation

http://slidepdf.com/reader/full/csc-248-assignment-2-documentation 10/16

10

Page 11: Csc 248 Assignment 2 Documentation

7/29/2019 Csc 248 Assignment 2 Documentation

http://slidepdf.com/reader/full/csc-248-assignment-2-documentation 11/16

11

The next sheet contains one user defined function. This function is used to identify or 

associate a range of cells with colours. From the image we can see there are 4 sports houses

and their colours and the points won are highlighted in the houses colour and this helps to

find what house number the student belongs to.

Page 12: Csc 248 Assignment 2 Documentation

7/29/2019 Csc 248 Assignment 2 Documentation

http://slidepdf.com/reader/full/csc-248-assignment-2-documentation 12/16

12

In the last sheet, there is also one user defined function, this function was created to find out

how many cells were being selected at any moment. It is activated by the click of its button

Page 13: Csc 248 Assignment 2 Documentation

7/29/2019 Csc 248 Assignment 2 Documentation

http://slidepdf.com/reader/full/csc-248-assignment-2-documentation 13/16

13

and if one cell is being selected then a dialog box would show "1 cell selected". If more than

1 cell is selected, a dialog box would show "multiple cells selected.

Page 14: Csc 248 Assignment 2 Documentation

7/29/2019 Csc 248 Assignment 2 Documentation

http://slidepdf.com/reader/full/csc-248-assignment-2-documentation 14/16

14

Page 15: Csc 248 Assignment 2 Documentation

7/29/2019 Csc 248 Assignment 2 Documentation

http://slidepdf.com/reader/full/csc-248-assignment-2-documentation 15/16

15

Conclusion

To conclude, I would have to say that I have learnt the power of VBA and how limitless it is

and how much can be achieved through it and I know that it is a very important tool for everyone to get familiar with because it makes Microsoft office more personalized and easier 

to execute tasks. 

Page 16: Csc 248 Assignment 2 Documentation

7/29/2019 Csc 248 Assignment 2 Documentation

http://slidepdf.com/reader/full/csc-248-assignment-2-documentation 16/16

16

References

Chinowsky, B. (2009). Getting Started with VBA in Excel 2010. Retrieved from Microsoft

office Dev center: http://msdn.microsoft.com/en-us/library/office/ee814737.aspx

Visual Basic for Applications. (2012). Retrieved from wikipedia:

http://en.wikipedia.org/wiki/Visual_Basic_for_Applications