Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - bbasujon

Pages: 1 ... 6 7 [8] 9 10 ... 107
106
Microsoft Office Excel / Deleting Empty Rows
« on: August 15, 2012, 05:46:53 PM »
To delete empty rows between data:

1. Select all columns containing data.
2. Click the Sort icon (either Ascending or Descending).

Screenshot // Deleting Empty Rows


107
Problem:

Calculating the difference between each pair of dates listed in columns
A & B.

Solution:

To calculate the difference in days, use the DATEDIF function as shown in the following formula:
=DATEDIF(A2,B2,"d")

To calculate the difference in weeks, use the INT function as shown in the following formula:
=INT((B2-A2)/7)

To calculate the difference in months, use the DATEDIF function as shown in the following formula:
=DATEDIF(A2,B2,"m")

To calculate the difference in years, use one of the following two solutions:
Use the DATEDIF function as shown in the following formula:
=DATEDIF(A2,B2,"y")

OR

Use the YEAR, MONTH, AND, and DAY functions as shown in the following formula:

=YEAR(B2)-YEAR(A2)-(MONTH(B2) To calculate the number of months over years, use the DATEDIF function as shown in the following formula:
=DATEDIF(A2,B2,"ym")

To calculate the number of days over years, use the DATEDIF function as shown in the following formula:
=DATEDIF(A2,B2,"yd")

108
How Excel Works with Dates

Excel considers dates as numbers. Each date is assigned a unique serial number. For example, the 27th September 1999 was date serial 36430. Fortunately, you don't need to know this but the fact that all dates have numerical values can be very useful. Windows uses the 1900 date system in which 1st January 1900 is date serial 1, 2nd January 1900 is date serial 2 and so on.



When you type a date into a cell, Excel shows you a date but is thinking of a number.

To find out the serial number of a date, select the cell containing the date then go to Format > Cells. Go to the Number tab and click General in the Category list. The date's serial number will appear in the Sample box on the right.

You can make use of these numbers in all sorts of ways. You can add a number to a date to give a date that number of days later (or subtract a number to get a date before), you can take one date from another to find out how many days in between. There are lots of ready-made date functions too.
Working Out a Person's Age

A person's age is the amount of time since they were born (I know you know that but the computer doesn't, and we have to start thinking like the computer). So, all we have to do is put today's date in one cell and the person's date of birth in another cell, then take their date of birth away from today and you get their age - right? Well, sort of... you get a number. Because you took a date serial from another date serial you get the number of days in between*[note]. It looks like this...



In this example the formula in cell A3 is:

=A1-A2

 

 

We need to convert this number of days into a number of years. Most years have 365 days but every fourth year has 366 days. So the average number of years is 365.25. Let's modify our formula...






Note the brackets around the first part of the formula. Brackets mean "Work out this bit first...". I've used them here to stop Excel trying to divide A2 by 365.25 before taking it away from A1. Excel formulas work do any multiplying and dividing before it does adding and subtracting, but anything in brackets gets done first.

Now we can see a number of years, but it's still not quite right. We are getting an accurate result but we don't really want to see the fraction. As a last refinement we'll wrap the whole thing inside an INT() function to give us a whole number (an integer). This is better than changing the number of decimal places displayed, which would risk some numbers being rounded up and giving an incorrect result. Here's the finished result...



In this example the formula in cell A3 is:

=INT((A1-A2)/365.25)

 

 

*Note: In fact, to start with, you get another date. Confused? Don't be... Excel is trying to help but has misunderstood what we need. In date calculations, the result cell gets automatically formatted the same way as the first cell in the formula. Because the first cell was formatted as a date Excel showed you the result as a date, although you wanted to see a number. Just reformat the cell manually by going to Format > Cells > General. [back]

109
With the procedure below you can import data from an Access table to a worksheet.

Sub ADOImportFromAccessTable(DBFullName As String, _
    TableName As String, TargetRange As Range)
' Example: ADOImportFromAccessTable "C:\FolderName\DataBaseName.mdb", _
    "TableName", Range("C1")
Dim cn As ADODB.Connection, rs As ADODB.Recordset, intColIndex As Integer
    Set TargetRange = TargetRange.Cells(1, 1)
    ' open the database
    Set cn = New ADODB.Connection
    cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _
        DBFullName & ";"
    Set rs = New ADODB.Recordset
    With rs
        ' open the recordset
        .Open TableName, cn, adOpenStatic, adLockOptimistic, adCmdTable
        ' all records
        '.Open "SELECT * FROM " & TableName & _
            " WHERE [FieldName] = 'MyCriteria'", cn, , , adCmdText
        ' filter records
       
        RS2WS rs, TargetRange ' write data from the recordset to the worksheet
       
'        ' optional approach for Excel 2000 or later (RS2WS is not necessary)
'        For intColIndex = 0 To rs.Fields.Count - 1 ' the field names
'            TargetRange.Offset(0, intColIndex).Value = rs.Fields(intColIndex).Name
'        Next
'        TargetRange.Offset(1, 0).CopyFromRecordset rs ' the recordset data

    End With
    rs.Close
    Set rs = Nothing
    cn.Close
    Set cn = Nothing
End Sub

The macro examples assumes that your VBA project has added a reference to the ADO object library.
You can do this from within the VBE by selecting the menu Tools, References and selecting Microsoft
ActiveX Data Objects x.x Object Library.
Use ADO if you can choose between ADO and DAO for data import or export.

110
With the macro below it is possible to compare the content of two worksheets.
The result is displayed in a new workbook listing all cell differences.

Sub CompareWorksheets(ws1 As Worksheet, ws2 As Worksheet)
Dim r As Long, c As Integer
Dim lr1 As Long, lr2 As Long, lc1 As Integer, lc2 As Integer
Dim maxR As Long, maxC As Integer, cf1 As String, cf2 As String
Dim rptWB As Workbook, DiffCount As Long
    Application.ScreenUpdating = False
    Application.StatusBar = "Creating the report..."
    Set rptWB = Workbooks.Add
    Application.DisplayAlerts = False
    While Worksheets.Count > 1
        Worksheets(2).Delete
    Wend
    Application.DisplayAlerts = True
    With ws1.UsedRange
        lr1 = .Rows.Count
        lc1 = .Columns.Count
    End With
    With ws2.UsedRange
        lr2 = .Rows.Count
        lc2 = .Columns.Count
    End With
    maxR = lr1
    maxC = lc1
    If maxR < lr2 Then maxR = lr2
    If maxC < lc2 Then maxC = lc2
    DiffCount = 0
    For c = 1 To maxC
        Application.StatusBar = "Comparing cells " & Format(c / maxC, "0 %") & "..."
        For r = 1 To maxR
            cf1 = ""
            cf2 = ""
            On Error Resume Next
            cf1 = ws1.Cells(r, c).FormulaLocal
            cf2 = ws2.Cells(r, c).FormulaLocal
            On Error GoTo 0
            If cf1 <> cf2 Then
                DiffCount = DiffCount + 1
                Cells(r, c).Formula = "'" & cf1 & " <> " & cf2
            End If
        Next r
    Next c
    Application.StatusBar = "Formatting the report..."
    With Range(Cells(1, 1), Cells(maxR, maxC))
        .Interior.ColorIndex = 19
        With .Borders(xlEdgeTop)
            .LineStyle = xlContinuous
            .Weight = xlHairline
        End With
        With .Borders(xlEdgeRight)
            .LineStyle = xlContinuous
            .Weight = xlHairline
        End With
        With .Borders(xlEdgeLeft)
            .LineStyle = xlContinuous
            .Weight = xlHairline
        End With
        With .Borders(xlEdgeBottom)
            .LineStyle = xlContinuous
            .Weight = xlHairline
        End With
        On Error Resume Next
        With .Borders(xlInsideHorizontal)
            .LineStyle = xlContinuous
            .Weight = xlHairline
        End With
        With .Borders(xlInsideVertical)
            .LineStyle = xlContinuous
            .Weight = xlHairline
        End With
        On Error GoTo 0
    End With
    Columns("A:IV").ColumnWidth = 20
    rptWB.Saved = True
    If DiffCount = 0 Then
        rptWB.Close False
    End If
    Set rptWB = Nothing
    Application.StatusBar = False
    Application.ScreenUpdating = True
    MsgBox DiffCount & " cells contain different formulas!", vbInformation, _
        "Compare " & ws1.Name & " with " & ws2.Name
End Sub

This example macro shows how to use the macro above:

Sub TestCompareWorksheets()
    ' compare two different worksheets in the active workbook
    CompareWorksheets Worksheets("Sheet1"), Worksheets("Sheet2")
    ' compare two different worksheets in two different workbooks
    CompareWorksheets ActiveWorkbook.Worksheets("Sheet1"), _
        Workbooks("WorkBookName.xls").Worksheets("Sheet2")
End Sub

111
Simple amortization schedule

See screen shot 1.

Formulas that do not appear in the figure:

    The formula in cell C17 is =LOAN (LOAN is the name of cell C4).
    The formula in cell C18 is =G17; copy the formula from cell C18 to all the cells in column C, starting from C18.

Amortization schedule with a grace period

    The difference between a regular amortization schedule and one with a grace period is that in the latter, the repayment of the principal is delayed. The loan agreement stipulates the month in which the repayment of principal begins. The interest on the loan is calculated, and the first interest payment starts with the first month after the month that the loan was accepted.
    See screen shot 2. Note that the formulas used are not PPMT and IPMT; these formulas are not appropriate when the calculations are not linear.

Amortization schedule for random payment

    See the formulas in screen shot 3 for calculating the sum of the principal and interest in every payment.
    The dates of the loan repayment are random. The interest is calculated according to the number of interest days divided by 365 days in a year.

Screenshot // Create an Amortization Schedule in Microsoft Excel


112
Microsoft Office Excel / Close a workbook using VBA in Microsoft Excel
« on: August 15, 2012, 05:38:45 PM »
If you just want to close a workbook without the user being prompted for any confirmations
about saving the workbook you can simply do this :

ActiveWorkbook.Close False
' closes the active workbook without saving any changes

ActiveWorkbook.Close True
' closes the active workbook and saves any changes

ActiveWorkbook.Close
' closes the active workbook and lets the user decide if
' changes are to be saved or not

113
The VLookup formula returns data from any column you choose in the data table, simply change the number of the column in the third argument.

Although it sounds simple, there is a catch.

    How can you determine the number of a column in a data table that contains numerous columns?
    How can you easily change the number of the column in the third argument of the VLookup formula?
    How can you easily change the column number in multiple formulas in a worksheet from which complex reports are prepared or in a sheet that contains multiple VLookup formulas?



Solution

Insert the Match formula in the third argument of the VLookup formula.


Step 1: Define 2 names, see screen shot


    Select Row 1, press Ctrl+F3, type the name Row1 in the Names in workbook field, and click OK.

    Select the data table by pressing Ctrl+*. Then press Ctrl+F3, enter Data in the Names in workbook field, and click OK.


Step 2: Enter the Match formula


    Open an adjacent worksheet, and select cell A1.

    In cell A1 type 4/1/2001.

    In cell B1, enter the formula =MATCH (A1, Row1, 0).
    (Be careful to enter the value 0 in the third argument to specify the search for an exact value.)

    Results of calculation: 7.


Step 3: Enter the Vlookup formula


    Enter the account number 201 into cell A2.

    Enter the formula =VLOOKUP(A2,Data,B1) in cell B2. In the third argument of the VLookup formula, select a cell which contains the Match formula.

    Calculation results: 7,981.


Step 4: Combine the formulas


    In the formula bar (Match formula) of cell B1, select the formula without the = sign, press Ctrl+C, and click the Cancel sign (from the left of the formula in the formula bar). Select cell B2, and in the formula bar, select the address B1.
    Press Ctrl+V and press Enter.

    The final result is a nested formula is
    =VLOOKUP (A2, Data, MATCH(A1, Row 1, 0))

    Screenshot // Combine the VLookup and Match formulas in Microsoft Excel

114
To add a formula (Calculated Field) as a new column in a PivotTable report:

1. Select a cell in the PivotTable report.
2. Press Alt+P to select PivotTable dropdown icon from Pivot Table toolbar, select Formulas, and then Calculated Field.
3. In the Insert Calculated Field dialog box, type the formula name in the Name box.
4. In the Fields list box, select the first field name to insert and click Insert Field. The field name is copied into the Formula box.
5. Type / (in this example), repeat step 4 to insert the second field into the formula, and then click OK.
6. To format the new field, select a cell in the field and click the Field Settings icon on the PivotTable toolbar.

CAUTION!
This option can some times return incorrect calculation results when using multiplying or dividing.
Screenshot // PivotTable report - Adding a Calculated Field


115
Microsoft Office Access / Why can't I append some records?
« on: August 15, 2012, 05:36:11 PM »
When you execute an append query, you may see a dialog giving reasons why some records were not inserted:



The dialog addresses four problem areas. This article explains each one, and how to solve them.
Type conversion failure

Access is having trouble putting the data into the fields because the field type does not match.

For example, if you have a Number or Date field, and the data you are importing contains:
   -
   Unknown
   N/A
these are not valid numbers or dates, so produce a "type conversion" error.

In practice, Access has problems with any data that is is not in pure format. If the numbers have a Dollar sign at the front or contain commas or spaces between the thousands, the import can fail. Similarly, dates that are not in the standard US format are likely to fail.

Sometimes you can work around these issues by importing the data into a table that has all Text type fields, and then typecasting the fields, using Val(), CVDate(), or reconstructing the dates with Left(), Mid(), Right(), and DateSerial(). For more on typecasting, see Calculated fields misinterpreted.
Key violations

The primary key must have a unique value. If you try to import a record where the primary key value is 9, and you already have a record where the primary key is 9, the import fails due to a violation of the primary key.

You can also violate a foreign key. For example, if you have a field that indicates which category a record belongs to, you will have created a table of categories, and established a relationship so only valid categories are allowed in this field. If the record you are importing has an invalid category, you have a violation of the foreign key.

You may have other unique indexes in your table as well. For example, an enrolment table might have a StudentID field (who is enrolled) and a ClassID field (what class they enrolled in), and you might create a unique index on the combination of StudentID + ClassID so you cannot have the same student enrolled twice in the one class. Now if the data you are importing has an existing combination of Student and Class, the import will fail with a violation of this unique index.
Lock violations

Lock violations occur when the data you are trying to import is already in use.

To solve this issue, make sure no other users have this database open, and close all other tables, queries, forms, and reports.

If the problem persists, Make sure you have set Default Record Locking to "No Locks" under File (Office Button) | Options | Advanced (Access 2007 or later), or in earlier versions: Tools | Options | Advanced.
Validation rule violations

There are several places to look to solve for this one:

    There is something in the Validation Rule of one of the fields, and the data you are trying to add does not meet this rule. The Validation Rule of each field is in the lower pane of table design window.

    There is something in the Validation Rule of the table, and the data you are trying to add does not meet this rule. The Validation Rule of the table is in the Properties box.

    The field has the Required property set to Yes, but the data has no value for that field.

    The field has the Allow Zero Length property set to No (as it should), but the data contains zero-length-strings instead of nulls.

If none of these apply, double-check the key violations above.
Still stuck?

If the problem data is not obvious, you might consider clicking Yes in the dialog shown at the beginning of this article. Access will create a table named Paste Errors or Import Errors or similar. Examining the specific records that failed should help to identify what went wrong.

After fixing the problems, you can then import the failed records, or restore a backup of the database and run the complete import again.

116
Microsoft Office Access / 10 Time-Saving Tips for Microsoft Access 2007
« on: August 15, 2012, 05:35:23 PM »
Looking to shave some time off your daily Microsoft Access administration and design tasks? There are many great, little-known features of this program that you can use to improve the efficiency of your database experience.

I've put together a collection of ten tips that will improve your Microsoft Access experience.
1. Automatically Add Timestamps To Database Records
There are many applications where you may wish to add a date/time stamp to each record, identifying the time that the record was added to the database. It’s easy to do this in Microsoft Access using the Now() function.
More Info
2. Build Your Databases from Templates
Why build a database from scratch when there are hundreds of templates available to help you get started? Microsoft Access includes a number of built-in templates which are complemented by a large number of templates made available by the Access user commmunity. It's much easier to build a database starting from the work of others than reinventing the wheel building your own from scratch!
More Info
3. Use SQL for Advanced Queries
If you're struggling to design a query in Microsoft Access, it's very helpful to have a working knowledge of the Structured Query Language (SQL) to fall back upon. This language is the foundation of all relational databases and using it allows you to exactly specify the results you wish to achieve.
More Info
4. Choose Primary Keys Carefully
The selection of a primary key is one of the most critical decisions you’ll make in the design of a new database. The most important constraint is that you must ensure that the selected key is unique. If it’s possible that two records (past, present, or future) may share the same value for an attribute, it’s a poor choice for a primary key. When evaluating this constraint, you should think creatively.
More Info
5. Import from Excel to Access
Let's face it: most of the data out there on user desktops is stored in Microsoft Excel spreadsheets. This easy-to-use tool is found on almost every office computer in the world. Did you know that it's easy to import data from Microsoft Excel spreadsheets into an Access database?
More Info
6. Export from Access to Excel
Just as you're likely to need to import data from an Excel spreadsheet, you're also going to find it handy to export data from Access to a spreadsheet at some point. Most Office users are familiar with Microsoft Excel while many have never used Access databases.
More Info
7. Convert Your Old Databases to ACCDB Format
The ACCDB database format introduced in Access 2007 provides a number of enhanced features over the older MDB format. In this article, I walk you through the process of converting an MDB format database to the new ACCDB format.
More Info
8. Backup Your Database Regularly
You store critical data in Access databases every day. Have you ever stopped to consider whether you're taking appropriate actions to protect your database in the event of a hardware failure, disaster, or other data loss? Microsoft Access provides built-in functionality to help you back up your databases and protect your organization. In this tutorial, I walk through the process of backing up an Access database.
More Info
9. Leverage the Power of Relationships
The true power of relational databases lies in their ability to track relationships (hence the name!) between data elements. However, many database users don’t understand how to take advantage of this functionality and simply use Access as an advanced spreadsheet. In this tutorial, I walk through the process of creating a relationship between two tables in an Access database.
More Info
10. Encrypt Your Database Content
Security-conscious database users have long called for the ability to use strong encryption in Microsoft Access. With the release of Access 2007, Microsoft answered these pleas and introduced a robust encryption feature that allows for the simple addition of a great deal of security to Access databases.

117
These database templates will help you kick-start your database development. Why reinvent the wheel when you can begin your project using a pre-built template?
Microsoft Access Genealogy Database Template
Are you interested in tracing your family roots but don’t have a good place to store all of your genealogical information? While there are several full-featured family tree software packages on the market, you can also use a free Microsoft Access template to create your own genealogy database on your computer. Microsoft’s already done most of...
The Rational Guide to Microsoft Office Access 2007 Templates
Zac Woodall's book provides an excellent introduction to creating and sharing Microsoft Access database templates. It's a wonderful reference for anyone who needs to occasionally or regularly design or develop Access templates.
Accounting Ledger Database Template
The Accounting Ledger Database Template for Access 2003 allows you to create a basic chart of accounts and transaction ledger. It's available for free from the Microsoft Access Templates library.
Asset Tracking Database Template
This asset tracking database template assists in property management to identify assets by owner and description.
Bookmarks Database Template
The Bookmarks Database Template for Access 2007 allows you to easily organize, rate and categorize websites for future reference. It's available for free from the Microsoft Access Templates library.
Bug Tracking Database
The bug tracking database allows you to use Microsoft Access to track open and closed bugs in a software development project.
Business Account Ledger Database Template
This business account ledger database template can help you get your business finances in order using Microsoft Access.
Call Tracking Database
This call tracking database template for Access 2007 allows you to keep track of incoming calls to a help desk, business or other organization. It tracks details including call time, status, priority and category.
Classroom Management Database Template
The free Classroom Management Database Template available from Microsoft allows Access 2003 (and later) users the ability to manage all aspects of a school’s class activity. The template includes the ability to track course instructors, students, grades, locations, times, terms and credit hours.
Contacts Database Template
Every organization needs some type of contacts database and this Access template serves as an excellent starting point.
Customer Service Database Template
This powerful customer service database tracks incoming customer calls and allows you to monitor problem resolution and track related calls.
Events Database Template
This events database template allows you to track past, current and future events in Microsoft Access 2007.
Expense Report Database Template
Microsoft offers a free expense report database template for Microsoft Access 2003. This template allows you to track expense reports by employee and expense category.
Music Collection Database
This music collection database template from Microsoft's Office Community allows you to track your music collection by recording name, artist, genre, label, year released and other criteria.
Faculty Database Template
This faculty database template is designed to assist educational institutions tracking information about faculty members.
Fundraising Database Template
Microsoft's Office Online provides a charitable contributions database template for Access 2007 that allows you to track your fundraising campaign. Organized into three major categories, the database allows you to track campaigns, contributors and donations.
Home Inventory Database Template
If you're looking to create an inventory of your possessions for insurance purposes, this home inventory database template provides an excellent starting point.
IT Inventory Database
This IT Inventory database template for Microsoft Access 2007 will help you organize your business' computer inventory. It includes tables for tracking workstations, servers, software and network information.
Issues Database Template
This database template from Microsoft allows you to track, assign, prioritize and monitor any type of issue that arises in a business application. This template could be used for a software bug tracking database, a project management tool or many other applications.
Lending Library Database Template
This database template for Microsoft Access is designed for libraries but can be used for any application where items are loaned to individuals. It keeps a lending history and tracks outstanding items.
Marketing Projects Database Template
This database template tracks project timetables and deliverables for a variety of clients.
Meeting Tracker Database
The Meeting Tracker sample database for Microsoft Access 2007 allows you to track all of the details associated with your meetings. It includes the ability to assign tasks to owners and teams, track attendance and print meeting reports.
Nutrition Database Template
Watching your waistline? This nutrition database template will help you track both your eating and exercise habits.
Personal Budget Database
This personal financial planning database allows you to track income and expenses against your budget targets using Microsoft Access.
Project Management Database Template
This project management database template for Access 2007 allows users to track multiple projects and assign tasks to different individuals.
Sales Pipeline Database Template
The sales pipeline database template from Microsoft allows Access users to track an organization's sales from prospecting through to closing.
Service Call Management Database Template
Looking for a database to track service calls for your business? Microsoft offers a free Service Call Management Database Template for users of Access 2003 (or later). This database tracks work orders including information on the customer, payments received and service notes.
Student Database Template
Microsoft's student database template can help schools and similar institutions track information about students. It's also an excellent starting point for any type of membership database.
Task Database Template
This simple database template allows the tracking of tasks assigned to individuals or teams.
Time Card Database Template
Looking for a database to track employee time and payroll? The time card Access database template from Microsoft offers a great starting point. This free Access 2007 database allows you to get started tracking employee information quickly.
Wedding Planner Database
The wedding planner database template allows you to track your guest list, invitations, gifts and thank-you cards. It allows you to plan seating arrangements, select a dress and compare prices on wedding items.

118
Microsoft Office Access / Microsoft Access Function Library: Abs()
« on: August 15, 2012, 05:34:13 PM »
Function: Abs()

Purpose: The Abs() function returns the absolute value of any numeric expression provided to it as an argument.

Usage: Abs(expression)

Returns: Absolute value (unsigned magnitude) of expression

Examples and Special Cases

    Abs(-10) = 10
    Abs(10) = 10
    Abs(0) = 0
    Abs(NULL) = NULL
    Abs(uninitialized variable) = 0

119
Microsoft Office Access / Microsoft Access Function Library: Array()
« on: August 15, 2012, 05:33:48 PM »
Function: Array()

Purpose: The Array() function is used to create an array from a comma-delimited list of elements.

Usage: Array(arguments)

Returns: Variant data type containing an array consisting of the elements in the comma-delimited list of arguments

Examples and Special Cases

 Dim MyArray as Variant

 MyArray = Array(15,16,17,18)

120
Microsoft Office Access / Microsoft Access Function Library: Asc()
« on: August 15, 2012, 05:33:22 PM »
unction: Asc()

Purpose: The Asc() function is used to obtain the integer value of the first character in a string.

Usage: Asc(string)

Returns: Integer ASCII character code corresponding to the first character in string.

Examples and Special Cases

 Asc("string") = 97

 Asc("String") = 83

 Asc("database") = 100

 Asc() causes a runtime error

Pages: 1 ... 6 7 [8] 9 10 ... 107