#1
|
|||
|
|||
Syntax to use OFFSET() in a cell formula?
Can you help me correct the syntax?
I am using CountIf() to count occurrences of a string in a range. =COUNTIF($A$4:$AB$54,TEXT(AD5,"")) <--this works fine. Now I want to add another condition, whether the cell, 3 cells to the right on the same row, has the string value of "x". I am having trouble using Offset() to make this work. This formula is broken. =COUNTIF($A$4:$AB$54,TEXT(AD5,""+TEXT(OFFSET AD5,-3,"x"))) Thank you in advance for help. -DL |
#2
|
|||
|
|||
OFFSET() inside of COUNTIF()
Update, I am a little closer. This formula doesn't throw an error, but also doesn't return a correct count.
=COUNTIF($A$4:$AB$54,TEXT(AD5,""+TEXT(OFFSET(Selec tion,0,1,1,1),"x"))) I think the problem is Excel needs to know which cell from which to offset. "Selection" does not seem to do the trick. So, maybe I need to know how to detect each cell as CountIF() iterates through the range. Am I on the right track? Thanks |
#3
|
|||
|
|||
Here's a reference I put together for using OFFSET():
Code:
OFFSET($A$1,ROW()-1,COLUMN()-1) : the 'current' cell (never use it, would probably cause a circular reference) OFFSET($A$1,ROW()-1,COLUMN()-2) : the cell to the left of the 'current' cell OFFSET($A$1,ROW()-1,COLUMN()-3) : the cell two columns to the left of the 'current' cell OFFSET($A$1,ROW()-1,COLUMN()) : the cell to the right of the 'current' cell OFFSET($A$1,ROW()-1,COLUMN()+1) : the cell two columns to the right of the 'current' cell OFFSET($A$1,ROW(),COLUMN()-1) : the cell beneath the 'current' cell OFFSET($A$1,ROW()-2,COLUMN()-1) : the cell above the 'current' cell Code:
OFFSET(reference, rows, cols, [height], [width]) The OFFSET function syntax has the following arguments: Reference Required. The reference from which you want to base the offset. Reference must refer to a cell or range of adjacent cells; otherwise, OFFSET returns the #VALUE! error value. Rows Required. The number of rows, up or down, that you want the upper-left cell to refer to. Using 5 as the rows argument specifies that the upper-left cell in the reference is five rows below reference. Rows can be positive (which means below the starting reference) or negative (which means above the starting reference). Cols Required. The number of columns, to the left or right, that you want the upper-left cell of the result to refer to. Using 5 as the cols argument specifies that the upper-left cell in the reference is five columns to the right of reference. Cols can be positive (which means to the right of the starting reference) or negative (which means to the left of the starting reference). Height Optional. The height, in number of rows, that you want the returned reference to be. Height must be a positive number. Width Optional. The width, in number of columns, that you want the returned reference to be. Width must be a positive number. Remarks If rows and cols offset reference over the edge of the worksheet, OFFSET returns the #REF! error value. If height or width is omitted, it is assumed to be the same height or width as reference. OFFSET doesn't actually move any cells or change the selection; it just returns a reference. OFFSET can be used with any function expecting a reference argument. For example, the formula SUM(OFFSET(C2,1,2,3,1)) calculates the total value of a 3-row by 1-column range that is 1 row below and 2 columns to the right of cell C2. |
#4
|
|||
|
|||
Offset()
CGM3, thanks for the reply.
I think your work is a help. But I am confused by the absolute cell reference $A$1. CountIf() is running through a range of multi columnar data. It might find a matching value in E5, or G7 or AB15, In this case the count would be 3. But we really don't want it to count unless the value in a cell 3 columns to the right is "x". I don't see how I can use an absolute cell reference, because we don't know where CountIf() will find a match. Thanks again for the example. -DL |
Tags |
countif(), offset() |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
formula help with total in same cell | jterr | Excel | 14 | 02-25-2013 05:43 PM |
Change formula cell range based on cell value | Scoth | Excel | 4 | 10-25-2012 07:51 AM |
Keep cell in formula constant | jprt68 | Excel | 1 | 06-26-2012 08:31 AM |
Vlookup, offset, match & countif | jujuwillis | Excel | 2 | 10-15-2011 11:06 AM |
Protect formula in cell? | markg2 | Excel | 4 | 05-24-2010 11:50 AM |