0% found this document useful (0 votes)
309 views16 pages

CSC 248 Assignment 2 Documentation

This document discusses using Visual Basic for Applications (VBA) in Microsoft Excel to automate tasks and create user-defined functions. It describes how to develop user-defined functions using VBA macros and modules. It then provides examples of functions created to transfer daily sales data between sheets, count unique entries in a list, sort and highlight cells, associate cells with colors based on content, and count selected cells. The conclusion emphasizes that VBA makes Microsoft Office applications more customizable and efficient.

Uploaded by

Teni Adelanwa
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
309 views16 pages

CSC 248 Assignment 2 Documentation

This document discusses using Visual Basic for Applications (VBA) in Microsoft Excel to automate tasks and create user-defined functions. It describes how to develop user-defined functions using VBA macros and modules. It then provides examples of functions created to transfer daily sales data between sheets, count unique entries in a list, sort and highlight cells, associate cells with colors based on content, and count selected cells. The conclusion emphasizes that VBA makes Microsoft Office applications more customizable and efficient.

Uploaded by

Teni Adelanwa
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

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

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
2

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.

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.

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.

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.

10

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.
11

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
12

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.

13

14

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.

15

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

16

You might also like