You are on page 1of 88

(Multiple)UTILITY BASED FORM with DE-CENTRALIZED DATA COLLECTION AND ANALYSIS

by Ankur verma (0902710018)

Ayushi Singhal (0902710029) Shaleen Gupta (0902710094) Dhananjay Kr. Dubey (1002710904)

Submitted to the Department of Computer Science & Engineering in partial fulfillment of the requirements for the degree of Bachelor of Technology in Computer Science & Engineering

Ajay Kumar Garg Engineering College, Ghaziabad Gautam Buddh Technical University May, 2013

TABLE OF CONTENTS

Page

ABSTRACT..................................................................................................................i ACKNOWLEDGEMENTS..........................................................................................ii DECLARATION..................................................................................................v CERTIFICATE............................................................................................................vi LIST OF TABLES.......................................................................................................................ix LIST OF FIGURES......................................................................................................................x LIST OF SYMBOLS...................................................................................................................xii LIST OF ABBREVIATIONS......................................................................................................xiii

DECLARATION

We hereby declare that this submission is our own work and that, to the best of our knowledge and belief, it contains no material previously published or written by another person nor material which to a substantial extent has been accepted for the award of any other degree or diploma of the university or other institute of higher learning, except where due acknowledgment has been made in the text.
Signature : Name :Ankur verma Roll No : 0902710018 Date :

Signature : Name : Ayushi Singhal Roll No : 0902710029

Date :
Signature : Name :Dhananjay Kr. Dubey Roll No : 1002710904 Date :

Signature : Name :Shaleen Gupta Roll No : 0902710094 Date :

CERTIFICATE

This is to certify that Project Report entitled (Multiple) utility based form for decentralized data collection and analysis which is submitted by Ankur Verma (0902710018), Ayushi Singhal (0902710029), Dhananjay Kr. Dubey (1002710904) and

Shaleen Gupta(0902710094) in partial fulfillment of the requirement for the award of degree B. Tech. in Department of University, Computer Science and Engineering of U. P. Technical

is a record of the candidate own work carried out by him under my/our

supervision. The matter embodied in this thesis is original and has not been submitted for the award of any other degree.

Supervisors:

Mr. Akhilesh Verma (Assistant Professor) CSE Department

Mr. Ajay Kumar Garg (Assistant Professor) CSE Department

Date:

Date:

ACKNOWLEDGEMENT
It gives us a great sense of pleasure to present the report of the B. Tech Project undertaken during B. Tech. Final Year. We owe special debt of gratitude to Mr. Akhilesh Verma, Department of Computer Science & Engineering, Ajay Kumar Garg Engineering College, Ghaziabad for his constant support and guidance throughout the course of our work. His sincerity, thoroughness and perseverance have been a constant source of inspiration for us. It is only their cognizant efforts that our endeavors have seen light of the day. We also take the opportunity to acknowledge the contribution of Professor B. M. Kalra, Head, Department of Computer Science & Engineering, Ajay Kumar Garg Engineering College, Ghaziabad for his full support and assistance during the development of the project. We also do not like to miss the opportunity to acknowledge the contribution of all faculty and staff members of the department for their kind assistance and cooperation during the development of our project. Last but not the least, we acknowledge our friends for their contribution in the completion of the project.

Signature : Name :Ankur Verma Roll No :0902710018 Date : Signature : Name : Ayushi singhal Roll No : 0902710029

Date :
Signature : Name :Dhananjay Kr. Dubey Roll No :1002710904 Date : Signature : Name :Shaleen Gupta Roll No : 0902710094 Date :

ABSTRACT

The project titled Multiple utility based form with de-centralized data collection and analysis aims to showcase certain basic concepts of VBA by successfully applying these in automation of usual office works. Our main objective is to develop educational software cum model which helps to use the data management approach which is available both online as well as offline for the user and also provide hands-on interactive experience to enhance understanding and knowledge of these powerful methods.

In most of the offices in varying domains the database are maintained largely within Excel sheets. Sometimes though, despite the rich set of features in the standard Excel user interface (UI), one might want to find an easier way to perform a mundane, repetitive task, or to perform some task that the UI does not seem to address.

Institutions like ours require manual updating of data and analysis henceforth. Fortunately, Office applications like Excel have Visual Basic for Applications (VBA), a programming language that gives us the ability to extend those applications. There are numerous domains where such an application can be used fruitfully and easing the maintenance and analysis of data. The application provides an interface that updates locally stored database (Excel File).

The difference in our application and traditionally used web based applications is their reliability on the availability of a working internet connection before any updating or addition Thus the limitation lies in its roots, i.e. No Internet Connection means No Work.

While these limitations may be resolved to a huge extent using our application where all the data is stored on Google Cloud (using Google Drive) and is required to be synchronised only on the first use or when an updating is done. That too happens automatically as soon as the working connection to internet is available. While in case of Internet unavailability the modifications and analysis can be done on the local level using a friendly user-Interface with VBA - Macros working behind it.

Introduction

Document Purpose
This document covers all the necessary details pertaining to the project and also describes the functionality in an orderly fashion.

Product Scope
This project works on VBA Technology . The main purpose of developing this software is to provide sorted, There are n number of application in our college .The application will
develop interface that update local cached database and will make final updation at the end of day in central database.

Intended Audience and Document Overview


This project covers up a wide section of the society. It is solely being developed for the normal users starting regular basis updation. Its simplicity and elegance just makes it a piece of cake for everyone who is going to use it. The rest of SRS contains about the project development, design, functionality, hardware and software requirements in a detailed manner.

E-R DIAGRAM FOR THE PROJECT

Why Use VBA in Excel 2010?


Microsoft Excel 2010 is an extremely powerful tool that you can use to manipulate, analyze, and present data. Sometimes though, despite the rich set of features in the standard Excel user interface (UI), you might want to find an easier way to perform a mundane, repetitive task, or to perform some task that the UI does not seem to address. Fortunately, 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 and some examples such as the ones in this article, many users find that learning even a small amount of VBA code makes their work easier and gives them the ability to do things in Office that they did not think were possible. Once you have learned some VBA, it becomes much easier to learn a whole lot moreso 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. Despite all of the good reasons to use VBA in Excel 2010, it is important to remember that the best solution to a problem might not involve VBA at all. Excel has a large range of features even without VBA, so even a power user is unlikely to be familiar with them all. Before you settle on a VBA solution, search the Help and online resources thoroughly to make sure that there is not a simpler way.

VBA Programming 101


You might think that writing code is mysterious or difficult, but the basic principles use every-day reasoning and are quite accessible. The Office 2010 applications are created in such a way that they expose things called objects that can receive instructions. You interact with applications by sending instructions to various objects in the application. These objects are many, varied, and flexible, but they have their limits. They can only do what they are designed to do, and they will only do what you instruct them to do.

Objects
Programming objects relate to each other systematically in a hierarchy called the object model of the application. The object model roughly mirrors what you see in the user interface; for example, the Excel object model contains the Application, Workbook, Sheet, and Chart objects, among many others. The object model is a conceptual map of the application and its capabilities.

Properties and Methods


You can manipulate objects by setting their Properties and calling their Methods. Setting a property changes some quality of the object. Calling a method causes the object to perform some action. For example, theWorkbook object has a Close method that closes the workbook, and an ActiveSheet property that represents the sheet that is currently active in the workbook.

Collections
Many objects come in both singular and plural versionsWorkbook and Workbooks, Worksheet and Worksheets, and so on. The plural versions are called collections. Collection objects are used to perform an action on multiple items in the collection. Later on, this article discusses how to use the Worksheets collection to change the name of each worksheet in a workbook.

Macros and the Visual Basic Editor


Now that you know something about how Microsoft Excel 2010 exposes its object model, you can try calling object methods and setting object properties. To do so, you must write your code in a place and in a way that Office can understand; typically, by using the Visual Basic Editor. Although it is installed by default, many users do not know that it is even available until it is enabled on the ribbon.

Developer Tab
All Office 2010 applications use the ribbon. One tab on the ribbon is the Developer tab, where you access the Visual Basic Editor and other developer tools. Because Office 2010 does not display the Developer tab by default, you must enable it using the following procedure:

To enable the Developer tab


1. On the File tab, choose Options to open the Excel Options dialog box. 2. Click Customize Ribbon on the left side of the dialog box. 3. Under Choose commands from on the left side of the dialog box, select Popular Commands. 4. Under Customize the ribbon on the right side of the dialog box, select Main tabs, and then select theDeveloper check box. 5. Click OK. After Excel displays the Developer tab, note the location of the Visual Basic, Macros, and Macro Securitybuttons on the tab.

Figure 1. Developer tab in Excel 2010

Security Issues

Click the Macro Security button to specify which macros can run and under what conditions. Although rogue macro code can seriously damage your computer, security conditions that prevent you from running helpful macros can seriously undermine your productivity. Macro security is a complex and involved topic that you should study and understand if you work with Excel macros. For the purposes of this article, be aware that if the Security Warning: Macros have been disabled bar appears between the ribbon and the worksheet when you open a workbook that contains a macro, you can click the Enable Content button to enable the macros. Also, as a security measure, you cannot save a macro in the default Excel file format (.xlsx); instead, you must save the macro in a file with a special extension, .xlsm.

Visual Basic Editor


This following procedure shows you how to create a new blank workbook in which to store your macros. You can then save the workbook in the .xlsm format.

To create a new blank workbook using Macros


1. Click the Macros button on the Developer tab. 2. In the Macro dialog box that appears, type, Hello under Macro Name. 3. Click the Create button to open the Visual Basic Editor with the outlines of a new macro already typed in. VBA is a full-featured programming language with a correspondingly full-featured programming environment. This article examines only those tools that you use to get started with programming, and that excludes most of the tools in the Visual Basic Editor. With this caveat, close the Properties window on the left side of the Visual Basic Editor, and ignore the two dropdown lists that appear above the code.

Figure 2. Visual Basic Editor

The Visual Basic Editor contains the following code.


VB

Sub Hello() End Sub Sub stands for Subroutine, which you can define for now as "macro". Running the Hello macro runs any code that is between Sub Hello() and End Sub. Now edit the macro so that it looks similar to the following code.
VB

Sub Hello()

MsgBox ("Hello, world!") End Sub Go back to the Developer tab in Excel and click the Macros button again. Select the Hello macro in the list that appears and then click Run to display a small message box that contains the text, "Hello, world!" You just created and implemented custom VBA code in Excel. Click OK in the message box to close it and finish running the macro. If the message box does not appear, check your macro security settings and restart Excel.

Making Macros Accessible


You can also get to the Macros dialog box from the View tab, but if you use a macro frequently, you might find it more convenient to access it with a keyboard shortcut or a Quick Access Toolbar button. To create a button for the Hello macro on the Quick Access Toolbar, use the following procedure. The following procedure describes how to make a button for a macro on the Quick Access Toolbar:

To create a button for a macro on the Quick Access Toolbar


1. Click the File tab. 2. Click Options to open the Excel Options dialog box, and then click Quick Access Toolbar. 3. In the list under Choose commands from:, choose Macros. Find the text that is similar to Book1!Helloin the list that appears and select that text. 4. Click the Add >> button to add the macro to the list on the right side, and then click the Modify button to select a button image to associate with the macro. 5. Click OK. You should see your new button on the Quick Access Toolbar above the File tab. Now you can quickly run your macro at any time without using the Developer tab

A Real-World Example
Suppose that you have a workbook that contains lists on a large number of worksheets and that you want to change the name of each worksheet to match the heading of the list on that worksheet. Not every worksheet has a list on it, but if it does, the heading is in cell B1, and if it does not, cell B1 is blank. The names of worksheets without lists should be left alone. Ordinarily, this could be a complex task that involves looking at each worksheet to see if it has a list, copying the name if it does, clicking the worksheet tab, and then pasting in the new name. Instead of performing all of those steps manually, use Excel VBA to rename the sheets automatically.

Learning about Objects


To solve a VBA programming problem, you must first find out which objects the code will manipulate. To research that information, an essential tool is the Excel Object Model Reference, which is part of the Excel 2007 Developer Reference on the Microsoft Developer Network (MSDN). These reference materials will be updated for Excel 2010 when it is publicly released, but the Excel 2007 Developer Reference is adequate for most Excel 2010 purposes.

Figure 3. Excel Object Model Reference on MSDN

The first step is to find out how to manipulate the particular objects that you need to work with to accomplish your task; for example, worksheets, worksheet names, cells, and cell contents. In Excel, there are at least two ways to approach the problem: Go directly to the Object Model Reference. Record some of the actions that you want to automate, see how the recorded code manipulates the objects, and then go to the Object Model Reference for more information. Opinions vary on which approach is preferable, but for now, try using the Macro Recorder first.

Using the Macro Recorder


Sometimes a simple recorded macro is all you need; in these cases, you do not even have to look at the code. More often, recording alone is not enough. Instead, it is a starting point in the following process.

To use the Macro Recorder as a starting point to your solution


1. 2. 3. 4. 5. Record the actions that you want to code. Review the code and find the lines that perform those actions. Delete the rest of the code. Modify the recorded code. Add variables, control structures, and other code that the Macro Recorder cannot record. Begin your investigation by recording a macro that renames a worksheet to New Name. You can then use the recorded macro to develop your own macro that renames multiple worksheets based on their contents.

To record a macro that renames a worksheet


1. Click Record Macro on the Developer tab. 2. Name the macro RenameWorksheets, rename Sheet1 to New Name, and click Stop Recording.

3. Go to the Developer or View tab, click the Macros button, and choose Edit to open the Visual Basic Editor. The code in the Visual Basic Editor should look similar to the following.
VB

Sub RenameWorksheets() ' ' RenameWorksheets Macro ' ' Sheets("Sheet1").Select Sheets("Sheet1").Name = "New Name" End Sub The first four lines after the Sub line are comments. Any line that begins with an apostrophe is a comment and has no effect on what the macro does. The main uses for comments are the following: To make the code easier to understand, not just for you, but for anyone else who might need to modify the code later. To temporarily disable a line of code (called commenting it out). The four comments in this recorded macro serve neither purpose, so delete them. The next line uses the Select method to select the Sheet1 member of the Sheets collection object. In VBA code, it is not generally necessary to select objects before manipulating them, even though that is what the Macro Recorder does. In other words, this line of code is redundant, so you can delete it as well. The last line of the recorded macro modifies the Name Property of the Sheet1 member of the Sheetscollection. This is the line to keep. After you make your changes, the recorded code should now look like the following.
VB

Sub RenameWorksheets() Sheets("Sheet1").Name = "New Name" End Sub Manually change the sheet called New Name back to Sheet1, then run the macro. The name should change back to New Name.

Modifying the Recorded Code


Now it is time to research the Sheets collection that the Macro Recorder used. The Sheets topic in the Object Model Reference includes the following text. "The Sheets collection can contain Chart or Worksheet objects. If you need to work with sheets of only one type, see the object topic for that sheet type." You are only working with Worksheets, so change the code to the following.
VB

Sub RenameWorksheets() Worksheets("Sheet1").Name = "New Name" End Sub

Looping
One limitation of the code up to this point is that it only makes a change to one worksheet. You could add another line for each worksheet that you want to rename, but what if you do

not know how many worksheets there are, or what their current names are? You need a way to apply some rule for each sheet in the workbook. VBA has a construction called a For Each loop that is ideal. The For Each loop examines each item in a collection object such as Worksheets and can be used to take an action (like change a name) to some or all of those items. For more information about the For Each loop, see the VBA Language Reference. Click "Visual Basic Conceptual Topics", then "Using For Each...Next Statements". Also, be aware that the VBA Language Reference, like the Object Model Reference, will amply repay the time that you spend browsing it, and is an excellent place to look for ideas if you get stuck working on code. Using the third example in the "Using For Each...Next Statements" topic, edit the macro so that it looks similar to the following code.
VB

Sub RenameWorksheets() For Each myWorksheet In Worksheets myWorksheet.Name = "New Name" Next End Sub myWorksheet is a variable; that is, what it represents varies. In this case, the myWorksheet variable successively represents each worksheet in the Worksheets collection. You do not have to use myWorksheet; you could use "x", "ws", "WorksheetToRenameAfterTheContentsOfCellB1", or (with a few restrictions) almost any name that you want. A good rule of thumb is to use variable names that are long enough to remind you of what the variable stands for, but not so long as to clutter the code. If you run the macro in its current state, it produces an error because Excel requires each worksheet in a workbook to have a unique name, but the following line instructs Excel to give every worksheet the same name.
VB

myWorksheet.Name = "New Name" To correct the line so that you can verify that the For Each loop works, change the line to the following.
VB

myWorksheet.Name = myWorksheet.Name & "-changed" Instead of trying to give each worksheet the same name, this line changes the current name of each worksheet (myWorksheet.Name) to the current name with "-changed" appended to it.

Useful Renaming
The macro is getting close to something that might actually solve the problem at hand. What you need now is a way to take information from the worksheets themselvesspecifically from cell B1 on each worksheetand put that information into the names of the worksheets. This time, instead of using the Macro Recorder to find out how to refer to a cell, take a guess and see if using the Cell object will work. It is a good guess, but if you open the Object Model Reference and search for the Cell object, you find that there is no Cell object! There is a CellFormat object though. The CellFormat object topic includes the following code in the first code sample.
VB

' Set the interior of cell A1 to yellow. Range("A1").Select

It turns out that you use Range to specify a range of cells or just one individual cell. Again, you do not need the .Select portion, but you do need to find out how to refer to the contents of the Range object, as opposed to the Range object itself. If you go to the Range object topic, you can read that Range has both Methodsand Properties. The contents of a Range is a thing, not an action, so it would probably be a Property. If you scan down through the list, you can see the Value property. So, try the following.
VB

Sub RenameWorksheets() For Each myWorksheet In Worksheets myWorksheet.Name = myWorksheet.Range("B1").Value Next End Sub You get an error if you run this on a workbook that contains worksheets where B1 is empty, because an emptyRange has a Value of "" (an empty text string), which is not a legal worksheet name. It is about time to create some sample data anyway. Make the three sheets in the workbook look similar to the figure below, and then run the macro.

Figure 4. Sample data for the RenameWorksheets macro

The worksheet names should change accordingly.

Checking for Empty Cells


As noted earlier, the macro fails if any of the B1 cells in the workbook are empty. Instead of manually checking every worksheet, you can code the macro to do it for you. Before the myWorksheet.Name line, add the following line of code.

VB

If myWorksheet.Range("B1").Value <> "" Then And after the myWorksheet.Name line add the following text.
VB

End If This is called an IfThen statement. The IfThen statement instructs Excel to do whatever is on the lines between the If line and the End If line, but only if the condition in the If line is met. In the example, the following line specifies the condition to meet.
VB

myWorksheet.Range("B1").Value <> "" The <> means "is not equal to", and the quotation marks with nothing between them represent an empty text string; that is, no text at all. Therefore, whatever lines of code come between the If and the End If will only be executed if the value in B1 is not equal to nothing; that is, if there is text in cell B1. For more information about the IfThen statement, see the VBA Language Reference. (The full name is "IfThenElse statement", where Else is an optional component.)

Variable Declarations
Another improvement that you should make to the macro is to put a declaration of the myWorksheet variable at the start of the macro.
VB

Dim myWorksheet As Worksheet Dim is short for "Dimension", and Worksheet is the type of this particular variable. This statement tells VBA what kind of entity myWorksheet represents. Note that after you type As, the Visual Basic Editor displays a popup that lists all the available variable types. That is an example of IntelliSense technology; that is, the Visual Basic Editor responds to what it determines you are trying to do and offers a list of appropriate options. You can choose an option from the list or just continue typing. Although variable declarations are not required in VBA, using them is strongly recommended! Variable declarations make it much easier to keep track of your variables and to track down bugs in the code. Also, be aware that if you declare a variable with an object type (like Worksheet), IntelliSense displays an appropriate list of properties and methods associated with that object if you use the object variable later in the macro.

Comments
The macro is complex enough now to include some comments that remind you what the code is doing. The number of comments to use is partly a matter of personal style, but in general, too many comments are better than too few. Code usually needs to be modified and updated over time. Without comments, it can be hard to understand what is going on in the code, especially if the person who modifies the code is not the same person who wrote it in the first place. Adding comments for the If condition and for the line that renames the worksheets, results in the following code.
VB

Sub RenameWorksheets() Dim myWorksheet As Worksheet For Each myWorksheet In Worksheets 'make sure that cell B1 is not empty

If myWorksheet.Range("B1").Value <> "" Then 'rename the worksheet to the contents of cell B1 myWorksheet.Name = myWorksheet.Range("B1").Value End If Next End Sub To test the macro, rename the worksheets back to Sheet1, Sheet2, and Sheet3 and delete the contents of cell B1 on one or more of the worksheets. Run the macro to verify that it renames the worksheets that have text in cell B1 and leaves the other worksheets alone. The macro works for any number of worksheets, with any combination of populated and empty B1 cells.

More Things that You Can Do with VBA


This section looks at a few more things that you can do with VBA in Excel 2010. The examples in this section are designed to give you a sense of the capabilities of VBA instead of focusing on specific real-world scenarios. You might find it helpful to review the information in the Object Model Reference about the objects in each step as you work through the examples.

Importance of Being Open


A good way to learn programming in general, and Excel VBA in particular, is a strategy where you try something, get it to work, and then ask yourself questions such as: What could I try next? What do I want to learn first, given how I want to use VBA? What might just be fun or interesting to know? What am I curious about? The reader is strongly encouraged to investigate whatever avenues open up on the path to knowledge.

Charts
One common task in Excel is to create a chart based on a range of cells. Create a new macro calledAssortedTasks and then type the following text in the Visual Basic Editor.
VB

Dim myChart As ChartObject Add a line to create the chart object and assign the myChart variable to it.
VB

Set myChart = ActiveSheet.ChartObjects.Add(100, 50, 200, 200) The numbers in the parentheses determine the position and size of the chart. The first two numbers are the coordinates of the top left corner, and the second two numbers are the width and height. Create a new blank worksheet and run the macro. The chart it creates is useless because the chart has no data. Delete the chart that you just created, and add the following lines to the end of the macro.
VB

With myChart .Chart.SetSourceData Source:=Selection End With

This is a common pattern in VBA programming. First, you create an object and assign it to a variable, then you use the WithEnd With construction to do things with the object. The example code instructs the chart to use the current selection for its data. (Selection is a value for the Source parameter of the SetSourceDatamethod, not a value of an object property, so VBA syntax requires that you use a colon and an equal sign (:=) instead of just an equal sign (=) to assign the value.) Type some numbers in cells A1:A5, select the cells, and then run the macro. The chart shows up as the default type, a bar chart.

Figure 5. Bar chart created by using VBA

If you do not like the bar chart, you can change it to some other kind of chart by using code that is similar to the following.
VB

With myChart .Chart.SetSourceData Source:=Selection .Chart.ChartType = xlPie End With xlPie is an example of a built-in constant, also known as an enumerated constant. There are many of these throughout Excel, and they are exhaustively documented. For more information about built-in constants, see the Enumerations section of the Object Model Reference. For example, the constants for chart types are listed under "XlChartType Enumeration". You can modify the data. For example, try adding this line right after the variable declaration.
VB

Application.ActiveSheet.Range("a4").Value = 8

You can get input from the user, and use that input to modify the data.
VB

myInput = InputBox("Please type a number:") Application.ActiveSheet.Range("a5").Value = myInput Finally, add the following lines to the end of the macro.
VB

ActiveWorkbook.Save ActiveWorkbook.Close The complete macro should now look something like the following.
VB

Sub AssortedTasks() Dim myChart As ChartObject Application.ActiveSheet.Range("a4").Value = 8 myInput = InputBox("Please type a number:") Application.ActiveSheet.Range("a5").Value = myInput Set myChart = ActiveSheet.ChartObjects.Add(100, 50, 200, 200) With myChart .Chart.SetSourceData Source:=Selection .Chart.ChartType = xlPie End With ActiveWorkbook.Save ActiveWorkbook.Close End Sub Verify that cells A1:A5 are still selected, run the macro, type a number in the input box, and then click OK. The code saves and closes the workbook. Reopen the workbook and note the change to the pie chart.

UserForms
The previous section showed how to use a simple input box to get input from the user. In addition to the corresponding message box that displays information, VBA provides extensive capabilities that you can use to create custom dialog boxes, to code controls that are placed directly on worksheets, or to manipulate the dialog boxes that are built in to Excel. For more information about these capabilities, see Controls, Dialog Boxes, and Forms in the Excel 2007 Developer Reference. This section completes this introductory look at Excel VBA by taking a quick look at UserForms. On the Developer tab, click the Visual Basic button to open the Visual Basic Editor, and then go to the Insertmenu and choose UserForm to open the UserForm Design View. You will see two windows. One represents the UserForm that you are creating and the other, the Toolbox, shows the various controls that you can add to your UserForm; for example, command buttons, option buttons, check boxes, and so on. You can move the mouse over a Toolbox control to see what type of control it creates. Create a very simple UserForm with a single button that runs the Hello macro from earlier in this article. In theToolbox, depress the the CommandButton control, and then drag it to the UserForm to create a command button. Right-click the command button and choose View Code.

The Sub that you see is a skeleton for an event procedure, which runs when a particular event occurs. In this case, as the name of the Sub indicates, the event that runs the code is a Click on CommandButton1. Add the following line to the event procedure.
VB

Run("Hello") The Visual Basic Editor should now look similar to the following.

Figure 6. CommandButton1_Click event procedure

Save the workbook, go to the Window menu, and choose UserForm1 (UserForm) to redisplay the UserForm. Click the green arrow on the toolbar to run the UserForm. When the dialog box appears, click the command button to run the Hello macro, which displays the "Hello, world!" message box. Close the message box to return to the running UserForm, then close the running UserForm to return to Design View.

What are Macros


According to Microsoft, "If you perform a task repeatedly in Excel, you can automate the task by using a macro. A macro is a series of Excel commands and instructions that you group together as a single command to accomplish a task automatically. Instead of manually performing a series of time-consuming, repetitive actions in Excel, you can create and run a single macro, in effect, a custom command, that accomplishes the task for you. "Here are some typical uses for macros:

To speed up routine editing and formatting To combine multiple commands; for example, inserting a table with a specific size and borders To automate a complex series of tasks."

Running Macros

Whenever you open any file that contains macros, Excel and Excel will warn you that the macros embedded may be malicious and harmful. If you downloaded your file from a dubious source (like freefreefreetermpapers.com), be sure to click Disable Macros. You'll still be able to view the document's contents, but all of the special bells and whistles associated with the file's macros will be disabled. You'll lose functionality, but there will be no security risk. If you know the file came from a legitimate source, and you can verify that the person who sent you the file himself doesn't have a virus that snuck into the file, you can go ahead and click Enable Macros. In order to permanently change your security levels, on a Windows machine go to Tools > Macro > Security and change it between High, Medium, and Low. Excel 2004 for Macs don't have these security levels; instead, you can change whether Excel warns you about macros or not by going to Excel > Preferences and then by switching to Security and unchecking the box for Warn before opening a file that contains macros. After the file has opened, you can navigate to Tools > Macro > Macros to see what Macros are contained inside the document. The example files will have pre-written macros. Select any one of them and click Run to see what it does. A Excel of caution: after you've run a macro in Excel, you cannot undo it; in Excel, you can only undo each step of the macro. Therefore, be very sure that the macro you're running has the intended effect you want; otherwise, save your document before running an untested macro so you can always revert back.

Microsoft Excel 2003/2004 Macros


Creating and Recording Macros
First, conceptualize what you want your macro to do. For example, you can write a macro to remove the annoying line breaks you might get when you copy items from your browser or email client. The easiest way to figure out how to set up a macro is to see what you normally do to complete the task. Then all you have to do is record the series of steps you normally do and have the macro repeat them. Note: Macros are code based; therefore, mouse clicks are very difficult to replicate in code; for example, if you want your macro to always start at the top of your document, you SHOULD NOT scroll up to the top and click at the very beginning of your document. You should use the keyboard equivalent, which in this case is for Windows users Ctrl + Home and for Mac users Apple + Home. Hopefully, you've figured out an easy series of keyboard commands to accomplish the task of removing the annoying line break. There are numerous ways to do it, but the easiest (and most correct) way is to first hit Ctrl + Down Arrow (Windows) or Apple + Down Arrow (Mac) to move the cursor to the start of the following line. You then hit the Backspace key to bring that line up, and then you finally hit a space to separate the Excels. That is one complete iteration of the task, because to remove the next line, you would hit Ctrl + Down / Apple + Down again and repeat the same tasks. (Note: The reason hitting the End or Home key to move to the beginning or end of a line and then following it with a Delete or Backspace is that there are times that a single "line" of text will physically take up more than one line on your screen, in which case hitting End or Home

doesn't guarantee that you'll be in the right place. If it works, that's great, but be forewarned that if things start acting strange, there's a logical reason as to why it's doing that. This note is good to remember when coding more complex actions. If things don't work the way you planned, always assume first that you are entering your series of keys incorrectly.) So now we know how to perform our macro and we've rehearsed it. Now it's time to turn on the "video camera" so to say and capture it. 1. Go to Tools > Macro > Record New Macro 2. Type in a descriptive macro name. 3. With the Store Macro In drop down menu, you can choose whether you want the macro to always be saved inside the file or within all documents. For now, just choose All Documents. (The difference is explained more in detail in the Installing External Macros section). 4. You now have the option of adding either a toolbar or keyboard shortcut to be associated with your macro. You can also skip this step and get right to recording by hitting OK. 5. Enter in your series of key combinations. In case you forgot, the key combinations should be: a. Ctrl + Down Arrow / Apple + Down Arrow b. Backspace c. Space 6. Hit the stop button once you've completed the task. You can now run your macro to test that it works. Assign a shortcut key to the macro (see section below) and then continue hitting the shortcut key or toolbar button to watch your macro quickly clean up all the annoying line breaks.

Excel Macro Examples


1. You want to insert a customized table into your document. You want it to have 3 rows and 3 columns, and the top left cell filled in with the Excels "A Table Made with Macros!" Essentially, you want it to look like this: A Table Made with Macros!

Answer: 1. Start recording. 2. Go to the Standard Toolbar and locate the Tables button and then click and drag out a 3 by 3 table. Or, go to Table > Insert > Table, fill out 3 for Rows and 3 for Columns and hit Ok. 3. Your cursor will automatically place itself in the first cell. Type in A Table Made with Macros! 4. Now go to Table > Table Properties 5. In the Table tab, click on the Borders and Shading button near the bottom. 6. Click on the Box style on the left and change the Width of the line to 3 pt.

7. Stop recording. 2. For this example, you have a chunk of text where you want to italicize everything that is between double quotes. Sometimes this is a single Excel and sometimes it's more than one. You then want to remove the double quotes after you're done. How do you do this? Answer: 1. Start recording 2. Edit > Find or Ctrl + F 3. Search for a double quote ( " ) 4. Close the search box and hit the right arrow key 5. Hit Enter to move the start of the quotes text onto the next line 6. Edit > Find or Ctrl + F again 7. Search for a double quote ( " ) again 8. Close the search box and hit the left arrow key 9. Hit enter to move the double quote onto the next line 10. Hit Ctrl + up arrow key. 11. The piece of text that was between the double quotes should be on one line now. Select it all by hitting Ctrl + Shift + Down 12. Ctrl + I or click Italicize on the Format toolbar 13. Now hit Ctrl + Up 14. Hit Backspace twice (or the Delete key above the Enter key if you use a Mac) 15. Hit Ctrl + Down 16. Hit Backspace once and Delete once 17. Stop Recording

Running Macros via Shortcut Keys and Toolbar Buttons


If you have a macro that you run many times during one session, say the remove line break macro from the previous example, you may find it tiresome to always have to run the macro via the Tools menu. Fortunately, you can associate your macro with either a keyboard shortcut key, meaning you can hold down a certain combination of keys to start the macro, or you can create a toolbar button which you can click to start the macro. To assign a shortcut key combination to a macro you have already created on a Windows version: 1. Go to Tools > Customize 2. Click the Keyboard button at the bottom. On a Mac Version 1. Go to Tools > Customize > Customize Keyboard Then: 1. Scroll down to Macros in the left pane. 2. Select the macro you want to assign a shortcut key and press the desired shortcut key in the field titled Press new shortcut key. 3. Hit assign if you're satisfied with the combination. Be sure you don't overwrite another more useful shortcut key. For example, you probably wouldn't want to assign a macro the shortcut key for Ctrl + B / Apple + B.

To associate a toolbar button with a macro you already have created on a Windows version: 1. Go to Tools > Customize On a Mac Version 1. Go to Tools > Customize > Customize Toolbars / Menus Then: 1. Click the Commands tab. 2. Scroll down on the left pane down to Macros. It should be near the bottom of the list. 3. After selecting Macros, you'll notice the right pane update to show all the macros in your global template. If the macro you wish to customize is not listed, it might be embedded in your document. If that's the case, change the Save In drop down menu to your document. 4. Just click, drag, and drop the macro to one of your toolbars and it will appear. 5. On a Windows version, to either rename it so it takes up less space on your toolbar or to change it to a graphic button, go back to Tools > Customize. Mac users can right click on the button at any time and choose Properties to change the name or the graphic. a. Windows users must right-click the button they want to change while inside the Customize menu. b. You can then select the Name field and edit it or change the button image. If you mess up, you can right-click the button and select Delete. Once you've edited its style to you satisfaction, you can now simply click the button to run the macro.

Installing External Macros


Generally, macros that get written are so specific to a particular users desired goals that they're of no use to most people. However, there are times when macros can act like plug-ins, adding functionality to a program rather than merely a set of customized tasks, or they're just really useful to just about anymore. Thus, if someone sends you a Excel or Excel file with a macro embedded within the file, you can extract that macro into your own Excel or Excel template, generally called Normal.dot. Every file you open in Excel or Excel is based on this default template, so if you place a macro into your Normal.dot template, that macro will be available for your use every time you open a new file from your computer. (But be aware: downloading macros from strangers can be a security risk. This cannot be emphasized enough.) 1. Open the file with the macros. 2. Go to Tools > Macro > Macros. 3. Click on Organizer. By default it should open with the Macro Project Items window. If not, select that tab. 4. All of the macros embedded within the files listed on the left. (There will likely be only one file called "NewMacros.") Select the ones you want and click Copy to copy them over to your Normal.dot template. If you get an error message saying the file cannot be copied, it's likely because a file with the name you're copying to already exists. If that is the case, rename one of the files and try copying again.

The next time you open Excel, the macro you imported will be available for use in every new document.

Embedding Macros into Files


After you've created your macro and closed Excel, you may have tried to pass along your Excel file to another person to show off your nifty programming tricks. Unfortunately, depending on how your options are set up, the other person may have never received your macro-fied documents. This is because when you save your macros, by default, they're embedded into your Normal.dot template. If you want the macro to stay attached to the file so you can send it to other people for them to use, you must specifically embed it into the file. It's basically the reverse process of installing a macro. 1. Tools > Macro > Macros 2. Click Organizer 3. Make sure you select the file you want macros to be saved into in the drop down on the left 4. Click on NewMacros on the Normal.dot pane on the right. 5. Click Copy to move all the macros in your Normal.dot to your file. If it says "Project item can not be copied," you must first delete or rename the existing copying of NewMacros on the right pane, and then copy it over. If there are macros that you have copied over that you don't want packaged with your file, you can delete individual macros: 1. 2. 3. 4. Go to Tools > Macro > Macros Switch to your document in the Macros In drop down menu. Select your filename in the Macros in drop down menu. Select any macros you don't want and hit Delete.

Microsoft Excel 2003/2004 Macros


Much of what we learned about macros in Microsoft Excel also holds true in Excel. However, there are some distinct differences.

Creating and Recording Macros


Just like with Excel macros, you must conceptualize what steps need to be done. However, there is one key difference: whereas with recording Excel macros, you weren't supposed to click anywhere on your screen with a mouse because each position in a Excel document isn't necessarily the same in another, you are absolutely allowed to click away while recording an Excel macro because every position on an Excel spreadsheet has a similar position in another spreadsheet. The cell A5 exists on all spreadsheets, therefore, if you somehow find that you

need to bold the text in cell A5 in all your documents, you can write a macro for that. However, if you want to write a macro that is more flexible and doesn't rely on all your documents looking the same, Excel allows you to toggle the Relative References button when you record. The Relative References option allows you to change data based upon what cell is initially selected. When you go to record, Excel will figure out what cells you're changing based upon how far they are away from the initial cell you had selected. This is great for performing the same action many times around similarly structured data within your spreadsheet. Once you're ready to record: 1. Go to Tools > Macros > Macro 2. Enter in a name, and if you want, a keyboard shortcut 3. Select where you want to save your macro from the Store In drop down menu. For almost all cases, you'll want to store it in This Workbook. 4. Like with Excel, a small two button window will appear. However, the second button is no longer a pause button, but the relative reference button we discussed. If your macro requires it, click it to change its highlighting to red indicating that it is toggled on. 5. Perform your actions. 6. Click the stop button.

Excel Macro Examples


1. You have data in cell A1 that you want to always be formatted a special way. You want it to be bold, size 22, white text on a green background, and centered across the top of your page so it looks like this:

Answer: 1. Start recording your macro 2. Since you'll be changing the same cell on all of your documents, you won't need to use relative references. Make sure that the relative references button is not highlighted in red. 3. Click on the A1 cell and start applying your special style. You can find all of these formatting options on your Formatting toolbar. 4. The only option that isn't available there is the ability to center across your page. To do this you need to merge together some cells in you're A row. Select across about 5 or 6 columns, from A1 to F1 or H1, right click the cells, and select Format Cells. 5. Switch to the Alignment tab and check the box for Merge Cells and hit OK. 2. There are times when you have already set up columns of data. Suppose you want to add them up using the Autosum feature and then Autofill in order to add up multiple columns quickly. However, suppose you had several of these columns all over your spreadsheet. How would you do this? Answer: 1. Since we'll be applying this macro to several places throughout your spreadsheet, a macro that does not utilize Relative References will not be very functional. Thus,

2. 3. 4. 5. 6.

before you begin recording, be aware of what cell is currently selected since it will be used by Excel to figure out how to affect the other cells. In this case, you want to select the cell directly beneath the columns to be added. Start recording your macro Toggle the Relative References button. Click on the Autosum button. Your column of data to be added will be actively highlighted. If it isn't highlighted correctly, manually change it. Hit Enter. Autofill across so that Autosum formula is replicated across the appropriate columns. Stop recording.

Now, if we want to use this macro in another place in our spreadsheet, we just need to position our active cell in the position right under a column of data and then run the macro.

Running Macros via Shortcut Keys and Toolbar Buttons


You can run macros the same way you would in Excel, but adding shortcut keys and buttons is slightly different. To add or edit a keyboard shortcut for a macro: 1. 2. 3. 4. Tools > Macro > Macros Click on the Macro you want to add a shortcut key for Click Options Change the shortcut key

To add a graphical button for a macro: 1. Tools > Customize on Windows or Tools > Customize > Customize Toolbars/Menus on a Mac 2. Click on the Commands tab 3. Click Macros in the left pane 4. Click and drag New Macro Item to your toolbar 5. Click on the new button you've created 6. A new dialog box appears; click on the macro you want to assign to that button a. To rename the button on a Windows version you must first open Tools > Customize and while inside the Customize menu, right-click the button you wish to change and click on the name field. Rename it appropriately. b. To rename the button or change its graphical icon on a Mac version, simply right-click the button at any time and select Properties. You can then change the appropriate options from the new window.

Installing External Macros

Unlike Excel, you cannot move a macro in one of your workbooks to Excel's master template so that it always is available when you open a new workbook. Instead, you must transfer macros between workbooks, and store them in each other individually. To do this: 1. 2. 3. 4. Tools > Macro > Visual Basic Editor On the top left pane, locate the file which holds the macro you want to transfer. Click the + sign to open up the folders underneath Locate the Modules Folder. Inside will be several files named "Module X" where X is a number. Double click one of them to see if it is the right macro you want copied 5. Click and drag it to the document you want it available in. 6. Save the new file.

Google Docs Spreadsheet Step by Step Formula Tutorial

Google Docs Spreadsheet Formula Tutorial

This tutorial covers the steps to creating and using formulas in a Google Docs Spreadsheet. It is intended for those with little or no experience in working with spreadsheet programs. A Google Docs Spreadsheet formula allows you to perform calculations on data entered into the spreadsheet. You can use a formula for basic number crunching, such as addition or subtraction, as well as more complex calculations such as payroll deductions or averaging a student's test results. In addition, if you change the data the spreadsheet will automatically recalculate the answer without you having to re-enter the formula. Following the step by step instructions on the following pages covers how to create and use a basic formula in a Google Doc Spreadsheet.

Google Spreadsheet Formula Tutorial: Step 1 of 3 The following example creates a basic formula. The steps used to create this basic formula are the same ones to follow when writing more complex formulas. The formula will first add the numbers 5 + 3 and then subtract 4. The final formula will look like this: = A1 + A2 - A3 Step 1: Entering the data Note: For help with this tutorial refer to the image above. Type the following data into the appropriate cell. A1 : 3 A2 : 2 A3 : 4

Google Spreadsheet Formula Tutorial: Step 2 of 3


When creating a formula in a Google Spreadsheet, you ALWAYS start by typing the equal sign. You type it in the cell where you want the answer to appear. Note: For help with this example refer to the image above. 1. Click on cell A4 (outlined in black in the image) with your mouse pointer. 2. Type the equal sign ( = ) in cell A4.

Google Spreadsheet Formula Tutorial: Step 3 of 3


Following the equal sign, we add in the cell references of the cells containing our data. By using the cell references of our data in the formula, the formula will automatically update the answer if the data in cells A1, A2, or A3 changes. The best way of adding cell references is by using the Google Spreadsheets feature called pointing. Pointing allows you to click with your mouse on the cell containing your data to add its cell reference to the formula. After the equal sign added in step 2 1. Click on cell A1 with the mouse pointer to enter the cell reference into the formula. 2. Type a plus ( + ) sign. 3. Click on cell A2 with the mouse pointer to enter the cell reference into the formula. 4. Type a minus ( - ) sign. 5. Click on cell A3 with the mouse pointer to enter the cell reference into the formula. 6. Press the ENTER key on the keyboard. 7. The answer 1 should appear in cell A4.

8. Click on cell A4. The complete formula = A1 + A2 - A3 is shown in the formula bar above the worksheet.

Google Cloud Connect


What is Google Cloud Connect? Google Cloud Connect is a plug-in for Microsoft Office 2003, 2007, and 2010 that lets you share and simultaneously edit Microsoft Word, PowerPoint, and Excel documents with other people in your organization. You get the collaboration benefits of Google Drive, while continuing to use Microsoft Office.

System requirements Google Cloud Connect works for Microsoft Word, PowerPoint, and Excel files for users of Microsoft Office 2003, 2007, and 2010. It supports Windows XP, Windows Vista, and Windows 7. It is currently not available for Macs. For more details, see System requirements. How does it work? Syncing and sharing documents: Google Cloud Connect tracks, manages, and syncs all changes on your Microsoft Office documents into one updated version for each document. Each document that you sync through Google Cloud Connect gets a unique URL, or web address, that you can share with collaborators through IM or email. Depending on the privacy setting youve selected for the document, other people will be able to click this link and view the document in the browser. Collaborating simultaneously on documents: Google Cloud Connect for Microsoft Office lets you easily share documents with other people. When you add someone as an editor in a document, they receive an e-mail letting them know that a document has been shared with them. From there, they can open a link to view the document in the browser, or if they want to make edits, they can download the document and open it in Microsoft Office. When another editor edits a document in Microsoft Office, all changes get synced to and will be reflected on your screen. Revision history: Using Google Cloud Connect, you can edit a document both online and offline. Every time you sync a document, the revisions of a document are stored so you can easily roll back to a previous version. You can retrieve and revert to any prior revision of a document at any time.

Collaborating on a document has become increasingly easy these past few years. You can work together on the same document using services like EtherPad, you can have your documents in the cloud using Google Docs or you can sync your documents in real-time using services like Dropbox and this is just naming a few. Another player in the field is Google Cloud Connect. Google Cloud Connect is a plugin for MS Office that connects your Office documents to your Google Docs. It serves both as a backup for your documents, and as a means to share, get feedback and collaborate on a document.

Synchronizing Google Doc With Excel


First, you will need to download the Google Cloud Connect plugin and install it on your computer. The installation takes some time, but you will end up with a new toolbar in all your MS Office applications. To get started, you will need to log into your Google account and give the plugin access to your Google Docs.

You will then get the chance to configure the global settings of the plugin. There isnt much to configure here, really you can choose to sync your documents manually or automatically, and you can decide where the files will be saved. This is also the place to go if you wish to associate Cloud Connect with a different Google account.

The Cloud Connect toolbar is quite obtrusive. If you want to hide it, look for the (very) small triangle in the bottom center part of the toolbar and click it. This will hide the toolbar, and you can click it again to unhide it at any time.

Syncing and Sharing Using Cloud Connect, you can create a new Word, Excel or PowerPoint document and sync it to the Google cloud or share it from within the document itself. Clicking the Sync button will sync your document to your Google Docs, and you will immediately get a link to it right in the Office window. The Share button will allow you to add people to this document. You can add many people at once, and choose whether theyll be able to edit the document or just view it.

When you sync your document to the cloud, it will appear in your Google Docs. You will now be able to access it and view it online, but you will not be able to edit the document using Google Docs. The document will be mingled with your other Google Docs, and you can tell them apart by the little icons on the left.

If viewing and sharing online is not enough, you can convert your Office Doc into a Google Doc easily, by clicking on Actions and creating a Google Docs copy. However, you will not be able to download this copy using Cloud Connect and work on it offline.

Downloading The newest feature of Cloud Connect is the ability to download documents from Google Docs into MS Office, right from the MS Office window. To do this, click on the huge Google Cloud Connect logo and choose Open from Google Docs.

Note again, that you cannot download your Google Docs into MS Office. To use this feature, you will need to have Office documents synced to your Google Docs first. When you have some of those, you will be able to choose the document you want to download, and get it to instantly open in Office.

Collaborating Cloud Connect can be used to work together on a document. If what you all like best is to work on your document in Office on your own computer, this could be the solution for you. Each person can download and edit the document, and then sync it to the cloud. If youre all working on it at the same time, you might get messages like this:

This is nice, because it makes it harder for several people working together on the same document to erase each others work, and it also keeps all the versions of the document, in

case you wish to revert. To access all the versions from within Office, click on the little page icon and choose See revision history.

Module

Dim lrow As Long Dim ws As Worksheet

Private Sub cmdadd_Click() Set ws = Worksheets("Sheet1") lrow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _ SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1

For Each cell In Range("a1:a" & Range("a65536").End(xlUp).Row) If Val(UserForm1.TextBox1.Value) = cell.Value Then UserForm1.TextBox1.SetFocus MsgBox "already stored information" Exit Sub End If Next

store (lrow) ComboBox1.AddItem TextBox1.Value Exit Sub End Sub

Private Sub cmdadup_Click() Set ws = Worksheets("Sheet1") UserForm2.Show End Sub

Private Sub cmddel_Click() Set ws = Worksheets("Sheet1") If ComboBox1.ListIndex = -1 Then MsgBox "no information to delete" End If

If ComboBox1.Value = "" Then MsgBox " pls chose a roll no first" Else: For Each cell In Range("a1:a" & Range("a65536").End(xlUp).Row) If ComboBox1.Value = cell.Value Then lrow = cell.Row End If Next ws.Rows(lrow).EntireRow.Delete ComboBox1.RemoveItem (ComboBox1.ListIndex) End If ComboBox1.ListIndex = 0 End Sub

Private Sub cmdfirst_Click() Set ws = Worksheets("Sheet1") lrow = 2 Me.TextBox1.Value = ws.Cells(lrow, 1) Me.TextBox2.Value = ws.Cells(lrow, 2) Me.cbobranch.Value = ws.Cells(lrow, 3) Me.ComboBox2.Value = ws.Cells(lrow, 4) Me.ComboBox3.Value = ws.Cells(lrow, 5) Me.ComboBox4.Value = ws.Cells(lrow, 6) Me.TextBox7.Value = ws.Cells(lrow, 7)

End Sub

Private Sub cmdlast_Click() Set ws = Worksheets("Sheet1") lrow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _ SearchDirection:=xlPrevious, LookIn:=xlValues).Row

Me.TextBox1.Value = ws.Cells(lrow, 1) Me.TextBox2.Value = ws.Cells(lrow, 2) Me.cbobranch.Value = ws.Cells(lrow, 3) Me.ComboBox2.Value = ws.Cells(lrow, 4) Me.ComboBox3.Value = ws.Cells(lrow, 5) Me.ComboBox4.Value = ws.Cells(lrow, 6) Me.TextBox7.Value = ws.Cells(lrow, 7) End Sub

Private Sub cmdnext_Click() Set ws = Worksheets("Sheet1") lrow = 2 For Each cell In Range("a1:a" & Range("a65536").End(xlUp).Row) If cell.Value = Val(Me.TextBox1.Value) Then lrow = cell.Row + 1 If lrow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _ SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1 Then

MsgBox "this is the last record" lrow = 2 End If End If Next Me.TextBox1.Value = ws.Cells(lrow, 1) Me.TextBox2.Value = ws.Cells(lrow, 2) Me.cbobranch.Value = ws.Cells(lrow, 3) Me.ComboBox2.Value = ws.Cells(lrow, 4) Me.ComboBox3.Value = ws.Cells(lrow, 5) Me.ComboBox4.Value = ws.Cells(lrow, 6) Me.TextBox7.Value = ws.Cells(lrow, 7)

End Sub

Private Sub cmdprev_Click() Set ws = Worksheets("Sheet1") lrow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _ SearchDirection:=xlPrevious, LookIn:=xlValues).Row For Each cell In Range("a1:a" & Range("a65536").End(xlUp).Row) If cell.Value = Val(Me.TextBox1.Value) Then lrow = cell.Row - 1 If lrow = 1 Then

MsgBox "this is the first record" lrow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _ SearchDirection:=xlPrevious, LookIn:=xlValues).Row End If End If Next Me.TextBox1.Value = ws.Cells(lrow, 1) Me.TextBox2.Value = ws.Cells(lrow, 2) Me.cbobranch.Value = ws.Cells(lrow, 3) Me.ComboBox2.Value = ws.Cells(lrow, 4) Me.ComboBox3.Value = ws.Cells(lrow, 5) Me.ComboBox4.Value = ws.Cells(lrow, 6) Me.TextBox7.Value = ws.Cells(lrow, 7) End Sub

Private Sub cmdupdate_Click() Set ws = Worksheets("Sheet1") If ComboBox1.Value = "" Then MsgBox " pls chose a roll no first" Else:

For Each cell In Range("a1:a" & Range("a65536").End(xlUp).Row) If Val(Me.ComboBox1.Value) = cell.Value Then lrow = cell.Row

End If Next

store (lrow)

Exit Sub End If End Sub

Private Sub ComboBox1_Change()

Dim ws As Worksheet Set ws = Worksheets("Sheet1") x=0 For Each cell In Range("a2:a" & Range("a65536").End(xlUp).Row) If cell.Value = Val(ComboBox1.Value) Then lrow = cell.Row x=1 End If Next If x = 0 Then MsgBox "no data exists with this id" lrow = 2 End If

Me.TextBox1.Value = ws.Cells(lrow, 1) Me.TextBox2.Value = ws.Cells(lrow, 2) Me.cbobranch.Value = ws.Cells(lrow, 3) Me.ComboBox2.Value = ws.Cells(lrow, 4) Me.ComboBox3.Value = ws.Cells(lrow, 5) Me.ComboBox4.Value = ws.Cells(lrow, 6) Me.TextBox7.Value = ws.Cells(lrow, 7) End Sub

Private Sub ComboBox2_Change()

End Sub

Private Sub CommandButton1_Click() Dim cControl As Control

For Each cControl In Me.Controls If cControl.Name Like "Text*" Then TextBox8.BackColor = vbRed End If Next End Sub

Private Sub UserForm_Initialize()

For Each cell In Range("a2:a" & Range("a65536").End(xlUp).Row) ComboBox1.AddItem cell.Value Next

cbobranch.AddItem "cse" cbobranch.AddItem "it" cbobranch.AddItem "ec" cbobranch.AddItem "en" cbobranch.AddItem "me"

With ComboBox2 .AddItem "a" .AddItem "b" .AddItem "c" .AddItem "d" .AddItem "e" .AddItem "f" .AddItem "g" .AddItem "h"

End With

With ComboBox3 .AddItem "1" .AddItem "2" .AddItem "3" .AddItem "4"

End With

With ComboBox4 .AddItem "1" .AddItem "2" .AddItem "3" .AddItem "4" .AddItem "5" .AddItem "6" .AddItem "7" .AddItem "8" End With

End Sub

Main Project

Forms

Authentic form

Fullform

Coding in Vba micros User form1

Student no cmbo box


Private Sub ComboBox1_Change() Dim ws As Worksheet Set ws = Worksheets("master") x=0 For Each cell In Range("e3:e" & Range("e65536").End(xlUp).Row) If cell.Value = Val(ComboBox1.Value) Then lrow = cell.Row x=1 Call image_load_combo End If Next If x = 0 Then MsgBox "no data exists with this id" lrow = 2 End If display (lrow)

End Sub

Private Sub CommandButton1_Click()

Dim ws As Worksheet

Set ws = Worksheets("master") Dim pict As Object x=0 For Each cell In Range("e3:e" & Range("e65536").End(xlUp).Row) If cell.Value = Val(ComboBox1.Value) Then lrow = cell.Row x=1 End If Next If x = 0 Then MsgBox "no data exists with this id" Else

End If

End Sub

Private Sub TextBox1_Change()

End Sub

Private Sub UserForm_Initialize()

Call GetActiveWorkbookPath Dim imageload_initial As String imageload_initial = GetFilePath & "images\" & "imagenotavailable.jpg" Me.Image1.Picture = LoadPicture(imageload_initial) Me.Image1.PictureSizeMode = fmPictureSizeModeStretch

For Each cell In Range("e3:e" & Range("e65536").End(xlUp).Row) ComboBox1.AddItem cell.Value Next

cbyn.AddItem "y" cbyn.AddItem "n"

Dim ctrl As Control For Each ctrl In Me.Controls If TypeName(ctrl) = "TextBox" Then ctrl.Enabled = False End If Next

End Sub Name of student Dim i As Integer Dim j As Integer Dim l As Integer Dim lrow As Integer Public GetFilePath As String

Sub GetActiveWorkbookPath() Dim FullPathFileName 'Dim GetFilePath

FullPathFileName = ActiveWorkbook.FullName GetFilePath = Mid(FullPathFileName, 1, InStrRev(FullPathFileName, "\")) ' MsgBox "Active Workbook Full Path = " & GetFilePath

End Sub

Sub image_load_non_combo() Call GetActiveWorkbookPath Dim loadimg_non_combo As String

loadimg_non_combo = GetFilePath & "images\" & TextBox1.Value & ".jpg"

Me.Image1.Picture = LoadPicture(loadimg_non_combo) Me.Image1.PictureSizeMode = fmPictureSizeModeStretch Image1.SpecialEffect = fmSpecialEffectRaised

End Sub

Sub image_load_combo() Call GetActiveWorkbookPath Dim loadimg As String loadimg = GetFilePath & "\images\" & ComboBox1.Value & ".jpg" 'MsgBox (loadimg) 'Worksheets(i).Name = temp & "-" & temp + 4

Me.Image1.Picture = LoadPicture(loadimg) Me.Image1.PictureSizeMode = fmPictureSizeModeStretch Image1.SpecialEffect = fmSpecialEffectRaised 'Me.Image1.Picture = LoadPicture("D:\RUNNING\910006.jpg")

End Sub Sub change_value_of_combobox_on_first_next_previous_last() ComboBox1.Value = TextBox1.Value

End Sub Private Sub clear() Dim z As Control For Each z In UserForm1.Controls If TypeName(z) = "TextBox" Then z.Value = "" End If Next z End Sub

Private Sub cbyn_Change() If cbyn.Value = "n" Then thn.Visible = False End If

If cbyn.Value = "y" Then thn.Visible = True End If

End Sub

Private Sub cmdadd_Click()

Dim ws As Worksheet Set ws = Worksheets("master") lrow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _ SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1

For Each cell In Range("e1:e" & Range("e65536").End(xlUp).Row) If Val(UserForm1.TextBox1.Value) = cell.Value Then UserForm1.TextBox1.SetFocus MsgBox "already stored information" Exit Sub End If Next

store (lrow) ComboBox1.AddItem TextBox1.Value Call clear End Sub

Private Sub cmdadup_Click() UserForm2.Show

End Sub

Private Sub cmddel_Click()

Dim lrow As Integer Dim ws As Worksheet

Set ws = Worksheets("master") If ComboBox1.ListIndex = -1 Then MsgBox "no information to delete" End If If ComboBox1.Value = "" Then MsgBox " pls chose a roll no first" Else: For Each cell In Range("e3:e" & Range("e65536").End(xlUp).Row) If Val(TextBox1.Value) = cell.Value Then lrow = cell.Row End If Next ws.Rows(lrow).EntireRow.Delete ComboBox1.RemoveItem (ComboBox1.ListIndex) End If ComboBox1.ListIndex = 0 Call clear End Sub

Private Sub cmdfirst_Click() lrow = 3

display (lrow) Call image_load_non_combo Call change_value_of_combobox_on_first_next_previous_last End Sub

Private Sub cmdlast_Click() Set ws = Worksheets("master") lrow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _ SearchDirection:=xlPrevious, LookIn:=xlValues).Row

display (lrow) Call image_load_non_combo Call change_value_of_combobox_on_first_next_previous_last End Sub

Private Sub cmdnext_Click() Set ws = Worksheets("master") lrow = 3 For Each cell In Range("e3:e" & Range("e65536").End(xlUp).Row) If cell.Value = Val(Me.TextBox1.Value) Then lrow = cell.Row + 1 If lrow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _ SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1 Then MsgBox "this is the last record"

lrow = 3 End If End If Next display (lrow) Call image_load_non_combo Call change_value_of_combobox_on_first_next_previous_last End Sub

Private Sub cmdprev_Click() Set ws = Worksheets("master") lrow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _ SearchDirection:=xlPrevious, LookIn:=xlValues).Row For Each cell In Range("e3:e" & Range("e65536").End(xlUp).Row) If cell.Value = Val(Me.TextBox1.Value) Then lrow = cell.Row - 1 If lrow = 2 Then MsgBox "this is the first record" lrow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _ SearchDirection:=xlPrevious, LookIn:=xlValues).Row End If End If Next display (lrow)

Call image_load_non_combo Call change_value_of_combobox_on_first_next_previous_last End Sub

Private Sub cmdup_Click() Set ws = Worksheets("master") If ComboBox1.Value = "" Then MsgBox " pls chose a roll no first" Else:

For Each cell In Range("e3:e" & Range("e65536").End(xlUp).Row) If Val(Me.ComboBox1.Value) = cell.Value Then lrow = cell.Row End If Next

store (lrow) End If

Call clear End Sub

Private Sub ComboBox1_Change() Dim ws As Worksheet

Set ws = Worksheets("master") x=0 For Each cell In Range("e3:e" & Range("e65536").End(xlUp).Row) If cell.Value = Val(ComboBox1.Value) Then lrow = cell.Row x=1 Call image_load_combo End If Next If x = 0 Then MsgBox "no data exists with this id" lrow = 2 End If display (lrow)

End Sub

Private Sub CommandButton1_Click()

Dim ws As Worksheet Set ws = Worksheets("master") Dim pict As Object x=0

For Each cell In Range("e3:e" & Range("e65536").End(xlUp).Row) If cell.Value = Val(ComboBox1.Value) Then lrow = cell.Row x=1 End If Next If x = 0 Then MsgBox "no data exists with this id" Else

End If

End Sub

Private Sub TextBox1_Change()

End Sub

Private Sub tnm_Change()

End Sub

Private Sub UserForm_Initialize() Call GetActiveWorkbookPath Dim imageload_initial As String imageload_initial = GetFilePath & "images\" & "imagenotavailable.jpg" Me.Image1.Picture = LoadPicture(imageload_initial) Me.Image1.PictureSizeMode = fmPictureSizeModeStretch

For Each cell In Range("e3:e" & Range("e65536").End(xlUp).Row) ComboBox1.AddItem cell.Value Next

cbyn.AddItem "y" cbyn.AddItem "n"

Dim ctrl As Control For Each ctrl In Me.Controls If TypeName(ctrl) = "TextBox" Then ctrl.Enabled = False End If Next

End Sub

Subject wise performance


Dim i As Integer Dim j As Integer Dim l As Integer Dim lrow As Integer Public GetFilePath As String

Sub GetActiveWorkbookPath() Dim FullPathFileName 'Dim GetFilePath

FullPathFileName = ActiveWorkbook.FullName GetFilePath = Mid(FullPathFileName, 1, InStrRev(FullPathFileName, "\")) ' MsgBox "Active Workbook Full Path = " & GetFilePath

End Sub

Sub image_load_non_combo() Call GetActiveWorkbookPath Dim loadimg_non_combo As String

loadimg_non_combo = GetFilePath & "images\" & TextBox1.Value & ".jpg"

Me.Image1.Picture = LoadPicture(loadimg_non_combo) Me.Image1.PictureSizeMode = fmPictureSizeModeStretch Image1.SpecialEffect = fmSpecialEffectRaised

End Sub

Sub image_load_combo() Call GetActiveWorkbookPath Dim loadimg As String loadimg = GetFilePath & "\images\" & ComboBox1.Value & ".jpg" 'MsgBox (loadimg) 'Worksheets(i).Name = temp & "-" & temp + 4

Me.Image1.Picture = LoadPicture(loadimg) Me.Image1.PictureSizeMode = fmPictureSizeModeStretch Image1.SpecialEffect = fmSpecialEffectRaised 'Me.Image1.Picture = LoadPicture("D:\RUNNING\910006.jpg")

End Sub Sub change_value_of_combobox_on_first_next_previous_last() ComboBox1.Value = TextBox1.Value

End Sub Private Sub clear() Dim z As Control For Each z In UserForm1.Controls If TypeName(z) = "TextBox" Then z.Value = "" End If Next z End Sub

Private Sub cbyn_Change() If cbyn.Value = "n" Then thn.Visible = False End If

If cbyn.Value = "y" Then thn.Visible = True End If

End Sub

Private Sub cmdadd_Click()

Dim ws As Worksheet Set ws = Worksheets("master") lrow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _ SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1

For Each cell In Range("e1:e" & Range("e65536").End(xlUp).Row) If Val(UserForm1.TextBox1.Value) = cell.Value Then UserForm1.TextBox1.SetFocus MsgBox "already stored information" Exit Sub End If Next

store (lrow) ComboBox1.AddItem TextBox1.Value Call clear End Sub

Private Sub cmdadup_Click() UserForm2.Show

End Sub

Private Sub cmddel_Click()

Dim lrow As Integer Dim ws As Worksheet

Set ws = Worksheets("master") If ComboBox1.ListIndex = -1 Then MsgBox "no information to delete" End If If ComboBox1.Value = "" Then MsgBox " pls chose a roll no first" Else: For Each cell In Range("e3:e" & Range("e65536").End(xlUp).Row) If Val(TextBox1.Value) = cell.Value Then lrow = cell.Row End If Next ws.Rows(lrow).EntireRow.Delete ComboBox1.RemoveItem (ComboBox1.ListIndex) End If ComboBox1.ListIndex = 0 Call clear End Sub

Private Sub cmdfirst_Click() lrow = 3

display (lrow) Call image_load_non_combo Call change_value_of_combobox_on_first_next_previous_last End Sub

Private Sub cmdlast_Click() Set ws = Worksheets("master") lrow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _ SearchDirection:=xlPrevious, LookIn:=xlValues).Row

display (lrow) Call image_load_non_combo Call change_value_of_combobox_on_first_next_previous_last End Sub

Private Sub cmdnext_Click() Set ws = Worksheets("master") lrow = 3 For Each cell In Range("e3:e" & Range("e65536").End(xlUp).Row) If cell.Value = Val(Me.TextBox1.Value) Then lrow = cell.Row + 1 If lrow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _ SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1 Then MsgBox "this is the last record"

lrow = 3 End If End If Next display (lrow) Call image_load_non_combo Call change_value_of_combobox_on_first_next_previous_last End Sub

Private Sub cmdprev_Click() Set ws = Worksheets("master") lrow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _ SearchDirection:=xlPrevious, LookIn:=xlValues).Row For Each cell In Range("e3:e" & Range("e65536").End(xlUp).Row) If cell.Value = Val(Me.TextBox1.Value) Then lrow = cell.Row - 1 If lrow = 2 Then MsgBox "this is the first record" lrow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _ SearchDirection:=xlPrevious, LookIn:=xlValues).Row End If End If Next display (lrow)

Call image_load_non_combo Call change_value_of_combobox_on_first_next_previous_last End Sub

Private Sub cmdup_Click() Set ws = Worksheets("master") If ComboBox1.Value = "" Then MsgBox " pls chose a roll no first" Else:

For Each cell In Range("e3:e" & Range("e65536").End(xlUp).Row) If Val(Me.ComboBox1.Value) = cell.Value Then lrow = cell.Row End If Next

store (lrow) End If

Call clear End Sub

Private Sub ComboBox1_Change() Dim ws As Worksheet

Set ws = Worksheets("master") x=0 For Each cell In Range("e3:e" & Range("e65536").End(xlUp).Row) If cell.Value = Val(ComboBox1.Value) Then lrow = cell.Row x=1 Call image_load_combo End If Next If x = 0 Then MsgBox "no data exists with this id" lrow = 2 End If display (lrow)

End Sub

Private Sub CommandButton1_Click()

Dim ws As Worksheet Set ws = Worksheets("master") Dim pict As Object x=0

For Each cell In Range("e3:e" & Range("e65536").End(xlUp).Row) If cell.Value = Val(ComboBox1.Value) Then lrow = cell.Row x=1 End If Next If x = 0 Then MsgBox "no data exists with this id" Else

End If

End Sub

Private Sub Label22_Click()

End Sub

Private Sub TextBox1_Change()

End Sub

Private Sub tnm_Change()

End Sub

Private Sub UserForm_Initialize() Call GetActiveWorkbookPath Dim imageload_initial As String imageload_initial = GetFilePath & "images\" & "imagenotavailable.jpg" Me.Image1.Picture = LoadPicture(imageload_initial) Me.Image1.PictureSizeMode = fmPictureSizeModeStretch

For Each cell In Range("e3:e" & Range("e65536").End(xlUp).Row) ComboBox1.AddItem cell.Value Next

cbyn.AddItem "y" cbyn.AddItem "n"

Dim ctrl As Control For Each ctrl In Me.Controls If TypeName(ctrl) = "TextBox" Then

ctrl.Enabled = False End If Next

End Sub

Snap Shot

User form1

User form2

Code of user form2


username

Private Sub cmdok_Click()

Dim ws As Worksheet Set ws = Worksheets("uidpass") Dim id As String id = Me.TextBox1.Value lrow = ws.Cells.Find(What:=id, SearchOrder:=xlRows, _ SearchDirection:=xlPrevious, LookIn:=xlValues).Row If lrow = "" Then MsgBox "invalid username" Else: If ws.Cells(lrow, 2) = TextBox2.Value Then

UserForm1.cmdadd.Visible = True UserForm1.cmdup.Visible = True

UserForm1.cmddel.Visible = True

Unload Me Dim ctrl As Control For Each ctrl In UserForm1.Controls If TypeName(ctrl) = "TextBox" Then ctrl.Enabled = True End If Next UserForm1.cbyn.Enabled = True Exit Sub Else: MsgBox "invalid password" End If End If

End Sub

Private Sub TextBox1_Change()

End Sub

Password
Private Sub cmdok_Click()

Dim ws As Worksheet Set ws = Worksheets("uidpass") Dim id As String id = Me.TextBox1.Value lrow = ws.Cells.Find(What:=id, SearchOrder:=xlRows, _ SearchDirection:=xlPrevious, LookIn:=xlValues).Row If lrow = "" Then MsgBox "invalid username" Else: If ws.Cells(lrow, 2) = TextBox2.Value Then

UserForm1.cmdadd.Visible = True UserForm1.cmdup.Visible = True UserForm1.cmddel.Visible = True

Unload Me Dim ctrl As Control For Each ctrl In UserForm1.Controls If TypeName(ctrl) = "TextBox" Then ctrl.Enabled = True End If Next UserForm1.cbyn.Enabled = True

Exit Sub Else: MsgBox "invalid password" End If End If

End Sub

Private Sub TextBox1_Change()

End Subsss

Private Sub TextBox2_Change()

End Sub

References:

Excel VBA Macro Programming By: Richard Shepherd Excel Macros 2007 made easy By: Gail Perry
http://en.wikipedia.org/wiki/Visual_Basic_for_Applications\

Excel Macro Programming for Dummies By: John Walkenbach

http://support.google.com/drive/bin/answer.py?hl=en&answer=1110327

You might also like