Excel Questions
Excel Questions
Yes, by using XLM's RUN function. For example, the following macro runs the Test
subroutine contained in Module1 in workbook Book1.xls:
=RUN(Book1.xls!Module1.Test)
Can I lock cells such that only specific users can modify them?
The same is also possible in excel 2003 or excel 2007,There is a option "Allow users to edit
ranges" can be used for this purpose.
You need to protect the workbook's structure. Select Tools - Protection - Protect Workbook.
In the Protect Workbook dialog box, make sure that the Structure checkbox is checked. If
you specify a password, that password will be required to unprotect the workbook.
* Add a sheet
* Delete a sheet
* Hide a sheet
* Unhide a sheet
* Rename a sheet
* Move a sheet
Where do I find resources or examples like sales report generation, purchase report
generation using excel.
Press F1, write sales report in search option & view the templates of sales report, but
connection of internet is must.
Ques 05. Code to find a Last used Row in a column or Last used column of a Row.
Solution: Last Row in a column can be find using End(xlUp) and Last Column in a row can be find
using End(xlToLeft). For e.g. Range("A1048576").End(xlUp).Row gives last used row of Column A.
Ques 11. How to hide a worksheet so that a user cannot unhide it?
Solution: Use Sheet's visible property and set it to xlSheetVeryHidden . For eg. Sheets(1).Visible
= xlSheetVeryHidden will super hide the first worksheet of the workbook.
Ques 13. Which are the 2 macro languages and which do you use ?
Solution: XLM (used in Excel 97 or before) and VBA(used for 2000 and after). Obviously, VBA is in
use these days.
Ques 14. Can you lock cells such that only specific users can modify them?
Solution: There is a option "Allow users to edit ranges" can be used for this purpose.
Ques 15. How can you add a drop-down list to a cell so the user can choose a value from the
list?
Solution: Using 'Data Validation'.
Ques 16. How can you increase the number of rows in a worksheet?
Solution: No one can't. They're fixed as 65536(2^16) in Excel 2003 or before and 1048576(2^20) in
Excel 2007 & Excel 2010.
Ques 17. How can you increase the number of columns in a worksheet?
Solution: No one can't. They're fixed as 256(2^8) in Excel 2003 or before and 16384(2^14) in Excel
2007 & Excel 2010.
Ques. 18. How will you distribute a workbook such that it can't be copied using macro or
anything?
Solution: We can create a workbook which cannot be modified but can not create a workbook
which can't be copied.(It depends on system security, it has nothing to do with Excel or VBA)
Ques 19. Your colleague created a dashboard and when you enter a value, it appears with two
decimal places. For example, when you enter 265 it shows up as 2.65. What's wrong?
Solution: By chance Excel's fixed-decimal mode was turned on. To return to normal,
Excel 2003 -->
Click Tools and then Options to display the Options dialog box.
Then click the Edit tab and remove the check mark from the "Fixed decimal " option.
Excel 2007 -->
Click Office button on Top-Left corner and click 'Excel Options'.
Go to Advanced and Uncheck 'Automatically insert a decimal point' option.
Excel 2010 -->
Click File button on Top-Left corner and click 'Excel Options'.
Go to Advanced and Uncheck 'Automatically insert a decimal point' option.
Of course, this feature can be useful when entering some types of data, but most of the time,
you'll want to keep the fixed-decimal mode turned off.
Ques 20. How can you prevent a user for adding or deleting sheets?
Solution: You need to protect the workbook's structure.
Excel 2003 -->
Select Tools - Protection - Protect Workbook. In the Protect Workbook dialog box, make sure that
the Structure checkbox is checked.
Excel 2007/2010 -->
Go to Review --> Click 'Protect Workbook' --> Click 'Protect Structure and Windows'
If you specify a password, that password will be required to unprotect the workbook. When a
workbook's structure is protected, the user may not:
* Add/Delete a sheet
* Hide/Unhide a sheet
* Rename a sheet
* Move a sheet
Ques 22. The Font dialog box allows you to select different Fonts, their style, their size, and
some other special effects. How do you bring up this Font dialog box?
Solution: Use Application.Dialogs(xlDialogFont).Show or
Application.Dialogs(xlDialogFormatFont).Show to load font dialog box from Excel VBA.
Ques 24. How to set the custom paper size in Excel Object through VB?
Solution: Activesheet.PageSetup.PaperSize = xlPaperLetter (Similarly xlPaperA4 or xlPaperLegal
etc.)
Ques 25. What is the method for returning more than one values from a function in VB?
Solution: Any of the three methods can be used:
i) Create a class with the properties you require to return and then return the object of the class
from the function.
ii) Using ByRef for the values.
iii) Return an array of the values.
Ques 27. To set the command button for ESC, Which property needs to be changed?
Solution: Set Cancel property of Button to True on the Form.
Ques 30. What is a Variant, what the pros and cons of its use?
Solution: Variant data type is able to hold any other data type, including numbers, strings, dates,
and object references. A Variant's descriptor is only 16 bytes long (4 short words for the type, and
2 long words for the data, or data pointer).
Pros: You cannot use Null with any variable type other than Variant.
You don't need to worry about what you have declared a variable as.
When a Variant has been declared but not assigned a value, it contains the special value Empty.
Cons: A developer may not remember and misuse a variable assigning any value to it which will be
type-casted without errors.
Ques 31. Give technical reasons which made Microsoft withdraw its support for VBA in Mac?
Solution: The reasons which made Microsoft drop its support to VBA are as follows, Microsoft
visual basic relies heavily on machine code which was written for Power PC architecture. Also it
would take another two years for developing VBA support for its architecture. It also states that
Microsoft will incorporate VBA in the next script of office release for Mac.
Excel determines dependencies by looking at the cells referred to by each formula and by the
argument list of each function.
Dependency trees are immediately updated whenever a formula is entered or changed.
To force the dependency trees to be rebuilt and all formulae calculation use CTRL+ALT+SHIFT+F9.
Ques 37. What are keyboard shortcuts and their equivalent VBA methods for Formulae
calculation and building Excel dependency trees?
Solution:
Most workbooks show a significant improvement in calculation speed on a system with multiple
cores. The degree of improvement depends on how many independent calculation trees the
workbook contains. If you make a workbook that contains one continuous chain of formulas, it will
not show any multithreaded calculation (MTC) performance gain, whereas a workbook that
contains several independent chains of formulas will show gains close to the number of processors
available.
Ques 46. What do you know about the interpretation features of VBA?
Solution: VBA is licensed to Microsoft and this compatible with and only Microsoft products. Code
written is compiled by an intermediate language called P-code and this is stored in hosting
applications such as Excel, Word and Access. The intermediate code is interpreted by a virtual
machine. This code and intermediate language is the exclusive right of Microsoft.
Ques 47. Explain about insert module and Goal Seek functions present in VBA?
Solution: The chief use of VBA is to make use of its special function which helps in repeated
actions. Goal seek function helps to reduce manual entry of the code each and every time. This
solves the problem of repeated function entry by automating functions and actions. Sub routines
are inserted into the using the VBA editor and command insert module.
Ques 48. State the difference between Visual Basic, VB Script and Visual Basic for
Applications?
Solution: Visual basic is useful if you are planning to develop your programs from scratch.This
language helps you in developing Active x controls, exe files, etc.
VB script is a powerful tool, through which you can create small scale applications on web pages,
automation applications, etc. Integrated development environment is not present for VB script.
Visual Basic for Applications are very useful in automating your existing application. VB
application is useful for developing already existing applications.
Ques 49. Write a macro to select all the non-blank cells of Activesheet ?
Solution:
Sub NonBlankCells()
On Error Resume Next
Union(Cells.SpecialCells(xlCellTypeFormulas, 23), Cells.SpecialCells(xlCellTypeConstants,
23)).Select
If Err.Number <> 0 Then
Cells.SpecialCells(xlCellTypeFormulas, 23).Select
Else
Exit Sub
End If
If Err.Number <> 0 Then
Cells.SpecialCells(xlCellTypeConstants, 23).Select
Else
Exit Sub
End If
On Error GoTo 0
End Sub
Ques 50. What is the difference between UsedRange and CurrentRegion properties ?
Solution:
i) The current region is a range bounded by any combination of blank rows and blank columns.
This property is useful for many operations that automatically expand the selection to include the
entire current region, such as the AutoFormat method. This property cannot be used on a
protected worksheet.
The UsedRange property is used to select the range of used cells on a worksheet. It returns a
Range object that represents the used range on the specified worksheet.
ii) Every non-blank cell got its CurrentRegion and its keyboard shortcut is Ctrl+Shift+Spacebar.
iii) There can be many current regions but there is only one used range in a worksheet
http://www.excelfunctions.net/ExcelFunction
s.html
Excel Text Functions
Functions to Remove Extra Characters Replacing / Substituting Parts of a Text String
WEEKNU YEARFRAC
Returns an integer representing the week Calculates the fraction of the year
M number (from 1 to 53) of the year from a represented by the number of
user-supplied date whole days between two dates
GCD Returns the Greatest Common Divisor of two Advanced Mathematical Operations
or more supplied numbers
SUMPRODUC Returns the sum of the products of
T corresponding values in two or more
LCM Returns the Least Common Multiple of two or
supplied arrays
more supplied numbers
SUM Returns the sum of a supplied list of SUMX2MY2 Returns the sum of the difference of
numbers squares of corresponding values in two
supplied arrays
EVEN Rounds a number away from zero (ie. RAND Returns a random number between 0
rounds a positive number up and a and 1
negative number down), to the next
even number
RANDBETWEE Returns a random number between two
N given integers
FLOOR Rounds a number towards zero, (ie.
rounds a positive number down and a Miscellaneous
negative number up), to a multiple of
significance
COMBIN Returns the number of combinations for a
given number of objects
FLOOR.PRECISE Rounds a number down, regardless of
the sign of the number, to a multiple of Returns a text string depicting the roman
ROMAN
significance (New in Excel 2010) numeral for a given number
INT Rounds a number down to the next ROUNDDOWN Rounds a number towards zero, (ie.
integer rounds a positive number down and a
negative number up), to a given number
MROUND Rounds a number up or down, to the of digits
nearest multiple of significance
ROUNDUP Rounds a number away from zero (ie.
ODD Rounds a number away from zero (ie. rounds a positive number up and a
rounds a positive number up and a negative number down), to a given
negative number down), to the next number of digits
odd number
TRUNC Truncates a number towards zero (ie.
ROUND Rounds a number up or down, to a rounds a positive number down and a
given number of digits negative number up), to the next integer.
FVSCHEDUL MIRR
Calculates the future value of an initial Calculates the internal rate of return for a
E principal, after applying a series of series of periodic cash flows, considering the
compound interest rates cost of the investment and the interest on the
reinvestment of cash
NPV Calculates the net present value of an
investment, based on a supplied discountXIRR Calculates the internal rate of return for a
rate, and a series of future payments and schedule of cash flows
income
Payment Functions
DB Calculates the depreciation of an asset for
a specified period, using the fixed-
CUMIPMT Calculates the cumulative interest paid
declining balance method
between two specified periods
CUMPRINC DDB
Calculates the cumulative principal paid on Calculates the depreciation of an asset for
a loan, between two specified periods a specified period, using the double-
declining balance method, or some other
user-specified method
IPMT Calculates the interest payment for a given
period of an investment, with periodic
constant payments and a constant interest SLN Returns the straight-line depreciation of an
rate asset for one period
ISPMT Returns the interest paid during a specified Returns the sum-of-years' digits
SYD
period of an investment depreciation of an asset for a specified
period
PMT Calculates the payments required to reduce
a loan, from a supplied present value to a
specified future value VDB Returns the depreciation of an asset for a
specified period, (including partial
periods), using the double-declining
PPMT Calculates the payment on the principal for balance method or another user-specified
a given investment, with periodic constant method
payments and a constant interest rate
Related Functions :
Basic Description
LOOKUP Function
VLOOKUP Function
The Excel HLOOKUP function 'looks up' a given value in the top row of a data array (or table), and returns the
corresponding value from another row of the array.
lookup_value - The value that you want to look for, in the first row of the supplied data
array
table_array - The data array or table, that you want to search the first row of, for the
supplied lookup_value
row_index_nu - The row number, within the supplied array, that you want the
m corresponding value to be returned from
Examples
Hlookup Example 1
Cells A2-F6 of the spreadsheet below, show the exam scores for 5 students in 4 different subjects. If you want
to look up a specific score (eg. Biology) for one of the students (eg. Ed), this can be done using the Hlookup
function, as shown in cell B10 of the spreadsheet.
In the example below, the formula is shown in cell B10 of the spreadsheet on the left, and the result is shown in
the spreadsheet on the right.
Formulas: Results:
In the above example, the Hlookup function searches through the top row of the table_array (the range A2-A6),
to find a match for the lookup_value (the name "Ed", in cell A10). When the the name 'Ed' is found, the function
returns the corresponding value from the 5th row of the lookup_table.
This is illustrated on the right. The function finds the name 'Ed' in the top row of the table_array and then
returns the value from the 5th row of the table_array.
If we change the name in the individual spreadsheet from 'Ed' to 'Cara', the Hlookup functions would
automatically recalculate the functions to display the exam results for Cara.
Hlookup Example 2
Cells A1-F3 of the spreadsheet below, show body types relating to body mass index (BMI), for the ranges
0 - 18.4, 18.5 - 24.9, 25.0 - 29.9 and over 30.
Cell C6 shows the user's current BMI, which is 23.5, and cell C7 shows the Hlookup function that is used to
look up the body type that relates to this BMI.
The Hlookup function in the above spreadsheet returns the result "Normal Weight", which is the correct body
type for a BMI of 23.5.
Note that, in this example, the range_lookup argument is set to TRUE, to tell that function that, if it cannot find
an exact match to the supplied lookup_value, it should use the closest match below this value. Therefore, for all
BMIs up to and including 18.4 the function would return "Underweight", for all BMIs between 18.5 and 24.9, the
function would return "Normal Weight", etc.
Trouble Shooting
If you get an error from the Excel Hlookup function this is likely to be one of the following :
Common Errors
#N/A - Occurs if the Hlookup function fails to find a match to the supplied lookup_value
if range_lookup = TRUE - the #N/A error is likely to be because the smallest value in the
(or is omitted) lookup row is greater than the supplied lookup_value
or
#REF! - Occurs if the supplied row_index_num argument is greater than the number of rows in the
supplied table_array
You can see the value that you want to look up in your table_array, but your Excel HLOOKUP is returning the #N/A error.
Why can't it 'see' the lookup_value in the table_array?
You may have unseen spaces at the start or end of either the value you are looking up, or in the cells of your table_array.
These spaces cause your lookup_value cell and the 'matching' cell in your table_array to have slightly different content.
Solution No. 1
Check the contents of the cells that you believe should match. If there are unseen additional spaces in one or both of the
lists, remove these using the TRIM function:
1. Create a new row or column next to the one with the additional spaces in it
2. Use the TRIM function in your new row or column, to get rid of extra spaces
3. Copy the contents of the new row or column and paste these over the top of the original row or column, using
paste->special->values
4. Delete the row or column containing the TRIM function
Solution No. 2
Force both sets of data to have the same type. For example, if you want both sets of values to be stored as text, convert
both sets of data to text, using Excel's Text To Columns tool:
1. Use the mouse to select the cells you want to convert to text (this must be done one column at a time)
2. From the Data tab at the top of your Excel workbook, select the Text to Columns ... option
3. Make sure the Delimited option is selected and click next
4. Make sure all the delimiter options are unselected and then click next again
5. You should now be offered a selection of Column Data Formats. Select Text and click the Finish button
The data in your selected cells should now be stored as text within Excel and so the Excel Hlookup function should be able
to 'look up' the matching value.
Note that you could have chosen to convert the contents of your cells to Excel's 'general' type, by simply selecting the
column data format General in the Text To Columns tool.
Basic Description
The Excel VLOOKUP function 'looks up' a given value in the left-hand column of a data array (or table), and
returns the corresponding value from another column of the array.
lookup_value - The value that you want to look for, in the left-hand column of the supplied
data array
table_array - The data array or table, that you want to search the left hand column of,
for the supplied lookup_value
col_index_nu - The column number, within the supplied array, that you want the
m corresponding value to be returned from
Vlookup Examples
Vlookup Example 1
In the spreadsheet below, columns A and B list an inventory of grocery items, and their prices, and cell E2 of
the spreadsheet shows a simple example of the Vlookup function being used to look up the price of an item
from the inventory.
The above Vlookup function returns the price for "Cornflakes", which is $3.50.
In this example:
- the lookup_value is the text string "Cornflakes", which is located in cell D2
- the col_index_num is set to 2, to denote that the value returned should be taken from column 2 of the
table_array
- the range_lookup argument is set to FALSE, to indicate that we only want a result to be returned if an
exact match to the lookup_value is found
Vlookup Example 2
In the spreadsheet below, columns A-C list the grades that are assigned to examination marks lying within the
ranges 0-44%, 45%-54%, etc.
Cell F2 shows the score of 52% that was achieved by the student "Anne" in an examination. The Vlookup
function in cell G2 looks up this score in column A of the spreadsheet and returns the associated grade from
column C. Note that, in this example, if the exact score of 52% is not found in column A, we want, instead, to
use the nearest value below this score.
The above Vlookup function returns the grade for the score 52%, which is E.
In this example:
- the lookup_value is the value 52%, which is located in cell F2
- the col_index_num is set to 3, to denote that the value returned should be taken from column 3 of the
table_array
- the range_lookup argument is set to TRUE, to indicate that, if an exact match to the lookup_value is not
found, we want to use the closest value below the lookup_value
Also, there are several further Vlookup examples on the Microsoft Office website.
Trouble Shooting
If you get a Vlookup error this is likely to be one of the following :
#N/A - Occurs if the Vlookup function fails to find a match to the supplied lookup_value
The cause of this will generally depend on the supplied [range_lookup] argument:
if [range_lookup] = TRUE - the #N/A error is likely to be because the smallest value in the
(or is omitted) left-hand column of the table_array is greater than the supplied
lookup_value
if [range_lookup] = FALSE - the #N/A error is likely to be because an exact match to the
lookup_value is not found in the left-hand column of the
table_array
If you still can't understand why you are getting this Vlookup error, check out the Vlookup
#N/A Error page
or
- the supplied col_index_num argument is greater than the number of columns in the
supplied table_array
or
If you need further help with this Vlookup error, check out the Vlookup #REF! Error page
The Excel GETPIVOTDATA function extracts data from an Excel Pivot Table
Data_field - The pivot table data field (ie. the value(s) in the center
of the table) that you want to retrieve
Note that, if the requested fields are not visible in the specified Pivot Table, the
Getpivotdata function returns the #REF! error.
The easiest way to input the Getpivotdata function is simply to type "=" into a cell and then
click on the Pivot Table value that you want to return. Excel automatically inserts the
Getpivotdata function into the active cell.
Examples
The examples below all refer to the following Pivot Table, which is located in columns A -
G of the current Excel Worksheet.
A B C D E F G
1
17
- Returns the value $357,520, which is the value of the Invoice Amount Total for all of the
Date field, "Jan".
- Returns the value $23,940, which is the value of the Invoice Amount Total for the Date
field, "Feb" and the Item Details field, "IPod".
- Returns the value $7,920, which is the value of the Invoice Amount Total for the Date
field, "Feb", the Item Details field, "IPod", and the Salesperson field "Kevin".
- Returns the Excel #REF! error as the Pivot Table doesn't show the totals for the
Salesperson "Kevin".