Sunday, September 15, 2013

Lock or unlock specific areas of a protected worksheet

Lock or unlock specific areas of a protected worksheet

When you protect a worksheet, all cells are locked by default, which means that they cannot be edited. To enable cells to be edited while leaving only some cells locked, you can unlock the cells and then lock only specific cells and ranges before you protect the worksheet. You can also enable specific users to edit specific ranges in a protected worksheet.
What do you want to do?

Lock only specific cells and ranges in a protected worksheet

  1. If the worksheet is protected, do the following:
  1. On the Review tab, in the Changes group, click Unprotect Sheet.
Excel Ribbon Image
 NOTE   Protect Sheet changes to Unprotect Sheet when a worksheet is protected.
  1. If prompted, type the password to unprotect the worksheet.
  1. Select the whole worksheet by clicking the Select All button.
Button image
  1. On the Home tab, in the Font group, click the Format Cell Font dialog box launcher Button image.
Excel Ribbon Image
Keyboard shortcut  You can also press CTRL+SHIFT+F or CTRL+1.
  1. On the Protection tab, clear the Locked check box, and then click OK.
 NOTE   This unlocks all the cells on the worksheet when you protect the worksheet.
  1. In the worksheet, select just the cells that you want to lock.
  2. On the Home tab, in the Font group, click the Dialog Box Launcher Button image next to Font.
Keyboard shortcut  You can also press CTRL+SHIFT+F or CTRL+1.
  1. On the Protection tab, select the Locked check box, and then click OK.
  2. On the Review tab, in the Changes group, click Protect Sheet.
Excel Ribbon Image
  1. In the Allow all users of this worksheet to list, select the elements that you want users to be able to change.
  1. In the Password to unprotect sheet box, type a password for the sheet, click OK, and then retype the password to confirm it.
 NOTES 
  • The password is optional. If you do not supply a password, then any user can unprotect the sheet and change the protected elements.
  • Make sure that you choose a password that is easy to remember, because if you lose the password, you cannot gain access to the protected elements on the worksheet.

Unlock ranges on a protected worksheet for users to edit

 IMPORTANT   To give specific users permission to edit ranges in a protected worksheet, your computer must be running Microsoft Windows XP or later, and your computer must be on a domain. Instead of using permissions that require a domain, you can also specify a password for a range.
  1. Select the worksheet that you want to protect.
  2. On the Review tab, in the Changes group, click Allow Users to Edit Ranges.
Excel Ribbon Image
 NOTE   This command is available only when the worksheet is not protected.
  1. Do one of the following:
    • To add a new editable range, click New.
    • To modify an existing editable range, select it in the Ranges unlocked by a password when sheet is protected box, and then click Modify.
    • To delete an editable range, select it in the Ranges unlocked by a password when sheet is protectedbox, and then click Delete.
  2. In the Title box, type the name for the range that you want to unlock.
  3. In the Refers to cells box, type an equal sign (=), and then type the reference of the range that you want to unlock.
 TIP   You can also click the Collapse Dialog button, select the range in the worksheet, and then click theCollapse Dialog button again to return to the dialog box.
  1. For password access, in the Range password box, type a password that allows access to the range.
 NOTE   Specifying a password is optional when you plan to use access permissions. Using a password allows you to see user credentials of any authorized person who edits the range.
  1. For access permissions, click Permissions, and then click Add.
  2. In the Enter the object names to select (examples) box, type the names of the users who you want to be able to edit the ranges.
 TIP   To see how user names should be entered, click examples. To verify that the names are correct, click Check Names.
  1. Click OK.
  2. To specify the type of permission for the user who you selected, in the Permissions box, select or clear theAllow or Deny check boxes, and then click Apply.
  3. Click OK two times.
 TIP   If prompted for a password, type the password that you specified.
  1. In the Allow Users to Edit Ranges dialog box, click Protect Sheet.
  2. In the Allow all users of this worksheet to list, select the elements that you want users to be able to change.
  1. In the Password to unprotect sheet box, type a password, click OK, and then retype the password to confirm it.
 NOTES 
  • The password is optional. If you do not supply a password, then any user can unprotect the worksheet and change the protected elements.
  • Make sure that you choose a password that you can remember, because if you lose the password, you cannot gain access to the protected elements on the worksheet.
 NOTES 
  • If a cell belongs to more than one range, users who are authorized to edit any of those ranges can edit the cell.
  • If a user tries to edit multiple cells at once and is authorized to edit some but not all of those cells, the user will be prompted to select and edit the cells one by one.

Friday, September 13, 2013

Search with conditional formatting

I would like to show you how to search a table using conditional formatting. The criteria highlight matching column and rows.
I am going to explain how to create the highlighting and the conditional formatting formulas behind.
Setting up the conditional formatting
  1. Select cell range A5:D25
  2. Go to tab "Home"
  3. Click "Conditional formatting" button
  4. Click "New Rule.."
  5. Click "Use formula to determine which cells to format"
  6. Type conditional formatting formula
  7. Click "Format..." button
  8. Select a color
  9. Click OK
  10. Click OK
Repeat above steps and create new conditional formatting rules with these formulas and colors:
and
Explaining conditional formatting formulas
It is important to understand how relative and absolute cell references work. Remember that cell range A5:D25 was selected before you created the conditional formatting rules.
The first conditional formatting formula:
=(A$5=$C$2)*($A5=$C$3)
Step 1 - Highlight cells that have a column header equal to the value in $C$2.
(A$5=$C$2)
The cell reference A$5 changes in each cell in cell range A5:D25 but remember only the column reference changes. This makes the formula comparing only the corresponding column header.
Example,
In cell B7, the cell reference changes to:
(B$5=$C$2)
becomes
"Company Name"="First Name"
and returns FALSE.
Step 2 - Highlight cells that have a Region value equal to the value in $C$3
($A5=$C$3)
The cell reference $A5 changes in each cell in cell range A5:D25, only the row reference changes.
Example,
In cell B7, the cell reference changes to:
($A7=$C$3)
becomes
"Europe"="Africa"
and returns FALSE.
Step 3 - Check if both criteria are TRUE
=(A$5=$C$2)*($A5=$C$3)
becomes
=FALSE*FALSE
and returns 0. Cell B7 is not highlighted with the selected color.
Download excel 2007 *.xlsx file

VLOOKUP - Select a table column with a drop down list (2/2)

VLOOKUP - Select a table column with a drop down list

The following sheet let´s you select a column in the table and the the value from that column is returned.
How to create the drop down list in cell B4
  1. Select cell B4
  2. Go to "Data" tab
  3. Click "Data Validation" button
  4. Select "List" i the drop down list
  5. Select source: =$C$8:$E$8
  6. Click OK
Array formula in cell C4:
=VLOOKUP(C2, IF(Table2[Region]=C3, Table2, ""), MATCH(B4, Table2[#Headers], 0), FALSE)
becomes
=VLOOKUP(C2, IF(Table2[Region]=C3, Table2, ""), MATCH(Company Name", {"Item","Region","Company Name","First Name","Last Name"}, 0), FALSE)
becomes
=VLOOKUP(C2, IF(Table2[Region]=C3, Table2, ""), 3, FALSE)
and returns "The New Firm"

VLOOKUP and a table (1/2)

VLOOKUP and a table

If you convert your cell range to a table you can add or remove as many records to the table as you want and the cell reference in the formula is automatically adjusted. Use the table name and table column name in the vlookup function to achieve this. See the formula bar in the picture below.
How to convert acell range to a table (Excel 2007 and above)
  1. Select cell range A7:E17
  2. Go to tab "Insert"
  3. Click table button
  4. Enable "My table has headers"
  5. Click OK

Vlookup with condition

VLOOKUP and a condition

The animated picture above shows you how the array formula removes specific records in the the table_array argument.
Array formula in C4:
=VLOOKUP(C2,IF(B8:B17=C3,A8:E17,""),3,FALSE)
becomes
=VLOOKUP("A",{"", "", "", "", "";"", "", "", "", "";"", "", "", "", "";"", "", "", "", "";"A", "South America", "The New Firm", "Tory", "Byrnes";"", "", "", "", "";"", "", "", "", "";"", "", "", "", "";"", "", "", "", "";"F", "South America", "Trans United Airways", "Ervin", "Hennessey"},3,FALSE)
and returns "The New Firm"
How to create an array formula
  1. Select cell C4
  2. Type the array formula
  3. Press and hold Ctrl + Shift
  4. Press Enter

Vlookup Explained

VLOOKUP - Introduction

The first example explains how the Vlookup function works.
VLOOKUP(lookup_valuetable_arraycol_index_num ,range_lookup)
The Vlookup function looks for a value in the leftmost column of a table and then returns a value in the same row from a column you specify.
lookup_value - is the value to be found in the first column of the table. This is one of the downsides using vlookup. I will show you how to look for a value in any column using INDEX and MATCH later in this post.
table_array - is a table of text, numbers or logical values. Table_array can be a cell reference or a range name. By modifying the table_array using an array formula we can use multiple conditions to create a "filtered" table_array. You can also use a table name, I´ll show you this later in this post.
col_index_num - is the column number in table_Array from which the matching value schould be returned.
range_lookup - is a logical value: Find the closest match in first column sorted in ascending order (TRUE) or find an exact match (FALSE)
Another downside with VLOOKUP is that it can only return the first value even if there are multiple matches, I made post a few years ago about this:
How to return multiple values using vlookup in excel
VLOOKUP(lookup_value, table_array, col_index_num ,range_lookup)
=VLOOKUP(C2, A8:E17, 3, FALSE)
This formula matches the value in cell C2 ("A") to the first column in cell range A8:E17. The second argument is the column number and the function returns the value from that column and in the same row. The last argument FALSE instructs the formula to look for an exact match.
=VLOOKUP(C2, A8:E17, 3, FALSE)
becomes
=VLOOKUP("A", {"A", "Australia", "Atlantic Corporation", "Birdie", "Schneider";"B", "North America", "Uplink Corporation", "Amshula", "Canty";"C", "Asia", "Omni Consumer Products", "Jaycee", "Martin";"D", "Europe", "Galaxy Corp", "Tracy", "Tuck";"A", "South America", "The New Firm", "Tory", "Byrnes";"B", "Australia", "ZiffCorp", "Santos", "Cowart";"C", "North America", "Minuteman Cafe", "Gen", "Lindgren";"D", "Asia", "Demo Company", "Edwin", "Shinn";"E", "Europe", "Western Gas & Electric", "Allayna", "Egan";"F", "South America", "Trans United Airways", "Ervin", "Hennessey"}, 3, FALSE)
and returns Atlantic Corporation.

Find date range

Hi Doctor Excel,
Need help with a formula Please.
I need to figure out the date range of a cell. So if cell "E2" has a date of 11/23/2012 then that would need to fall under date range of "11/19 - 11/25".
I have the following date range I need to identify: "11/12 - 11/18", "11/19 - 11/25", "11/26 - 12/2", "12/3 - 12/9", "12/10 - 12/16", "12/17 - 12/23", "12/24 - 1/1/2013".
I tried the formula below but I keep getting a result of "False". I appreciate any help I can get. Thank you
Answer:
Array formula in cell B2:
=TEXT(INDEX($D$2:$D$8, MATCH(1, IF((A2>=$D$2:$D$8)*(A2<=$E$2:$E$8), 1, 0), 0)), "MM/DD")&"-"&TEXT(INDEX($E$2:$E$8, MATCH(1, IF((A2>=$D$2:$D$8)*(A2<=$E$2:$E$8), 1, 0), 0)), "MM/DD")
How to create an array formula
  1. Select cell B2
  2. Click in formula bar
  3. Copy (Ctrl + c) and paste above formula (Ctrl + v) to formula bar
  4. Press and hold Ctrl + Shit
  5. Press Enter

Explaining array formula in cell B2

Step 1 - Find matching date range
IF((A2>=$D$2:$D$8)*(A2<=$E$2:$E$8),1,0)
returns
{0;1;0;0;0;0;0}
Step 2 - Find row
MATCH(1, IF((A2>=$D$2:$D$8)*(A2<=$E$2:$E$8), 1, 0), 0)
becomes
MATCH(1, {0;1;0;0;0;0;0}, 0)
and returns 2.
Step 3 - Return date
INDEX($D$2:$D$8, MATCH(1, IF((A2>=$D$2:$D$8)*(A2<=$E$2:$E$8), 1, 0), 0))
becomes
INDEX({41225; 41232; 41239; 41246; 41253; 41260; 41267}, 2)
and returns 41232.
Step 4 - Convert value to date format
TEXT(INDEX($D$2:$D$8, MATCH(1, IF((A2>=$D$2:$D$8)*(A2<=$E$2:$E$8), 1, 0), 0)), "MM/DD")
 becomes
TEXT(41232, "MM/DD")
and returns 11/19.

Download excel *.xlsx file

Lookup using multiple conditions

Question :
Hi Oscar,
I failed to search for "Ask" Section.. so submitting my query here.. Apologize for hijacking someones post,, and also for cross-post..
Can You please help me to create a drag-able FORMULA to get Margin.. via multiple Condition..
* Each Vendor has only one type of MARGIN decider (MRP or BRICK or TAX Code)
* According to Margin decider, I need to get MARGIN for the VENDOR..
i.e Vendor 1 (Chandoo) 's Margin Decider is BRICK..
If brick is ACC then Margin is 548, if Brick is JEW then Margin is 786.. (Check Table2 for lookupArea and Margin Decider..
Lookup multiple conditions1
LookUpArea..
Lookup multiple conditions2
* suggestion for changing Design of LookUpArea's is appreciable.
* use of HELPER column is also acceptable..
You can download the VBA version for your reference..
https://dl.dropbox.com/u/78831150/Excel/MultipleLookup.xlsm
Regards,
Deb

Answer:

Lookup multiple conditions3
Array formula in cell E2:
=INDEX($N$3:$N$11, MATCH(1, COUNTIFS(INDEX((B2, C2, D2), , , MATCH(TRUE, B2:D2<>"Need to Overlook", 0)), INDEX(($K$3:$K$11, $L$3:$L$11, $M$3:$M$11), , , MATCH(TRUE, B2:D2<>"Need to Overlook", 0)), A2, $J$3:$J$11), 0))
How to enter an array formula
  1. Select cell E2
  2. Paste array formula to formula bar
  3. Press and hold CTRL + SHIFT
  4. Press Enter
How to copy array formula
  1. Select cell E2
  2. Copy cell E2 (Ctrl + c)
  3. Select cell range E3:E23
  4. Paste (Ctrl + v)

Explaining array formula in cell E2

Step 1 - Determine which cell range to use
MATCH(TRUE, B2:D2<>"Need to Overlook", 0)
becomes
MATCH(TRUE, {"ACC","Need to Overlook","Need to Overlook"}<>"Need to Overlook", 0)
becomes
MATCH(TRUE, {TRUE,FALSE,FALSE}, 0)
and returns 1.
Step 2 - Return cell reference
INDEX((B2, C2, D2), , , MATCH(TRUE, B2:D2<>"Need to Overlook", 0))
becomes
INDEX((B2, C2, D2), , , 1)
and returns cell reference B2
Step 3 - Find matching row
COUNTIFS(INDEX((B2, C2, D2), , , MATCH(TRUE, B2:D2<>"Need to Overlook", 0)), INDEX(($K$3:$K$11, $L$3:$L$11, $M$3:$M$11), , , MATCH(TRUE, B2:D2<>"Need to Overlook", 0)), A2, $J$3:$J$11)
becomes
COUNTIFS(B2, $K$3:$K$11, A2, $J$3:$J$11)
and returns {1;0;0;0;0;0;0;0;0}
Step 4 - Calculate relative position of row
MATCH(1, COUNTIFS(INDEX((B2, C2, D2), , , MATCH(TRUE, B2:D2<>"Need to Overlook", 0)), INDEX(($K$3:$K$11, $L$3:$L$11, $M$3:$M$11), , , MATCH(TRUE, B2:D2<>"Need to Overlook", 0)), A2, $J$3:$J$11), 0)
becomes
MATCH(1, {1;0;0;0;0;0;0;0;0}, 0)
and returns 1.
Step 5 - Return margin value
=INDEX($N$3:$N$11, MATCH(1, COUNTIFS(INDEX((B2, C2, D2), , , MATCH(TRUE, B2:D2<>"Need to Overlook", 0)), INDEX(($K$3:$K$11, $L$3:$L$11, $M$3:$M$11), , , MATCH(TRUE, B2:D2<>"Need to Overlook", 0)), A2, $J$3:$J$11), 0))
becomes
=INDEX($N$3:$N$11, 1)
becomes
=INDEX({725; 588; 560; 616; 606; 731; 724; 646; 867}, 1)
and returns 725 in cell E2.

Download excel *.xlsx file

How to remove #num errors

Array formula:
=IFERROR(array_formula, "")