Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Row number in excel

Status
Not open for further replies.

CaitlinWhybrow

Technical User
Nov 18, 2002
9
GB
Hi

I have been trying in Excel to use the cell formula to return the row number of a cell:
Cell B32 contains the test "surname", so I thought that entering the formula: cell("row",'surname) which should return 32. It does sometimes, but sometimes, excel adds 1 to the number. Highlighting the cell with the formula shows that excel is refering to the column starting just below B32. But this doesn't seem to happen always, which is really confusing me. What am I missing??

Any advice would be really appreciated
 

Hi,

[tt]
=ROW()
=COLUMN()
[/tt]


Skip,

[glasses] [red]A palindrome gone wrong?[/red]
A man, a plan, a ROOT canal...
PULLEMALL![tongue]
 
From the help, Cell does this:
Code:
Returns information about the formatting, location, or contents of the upper-left cell in a reference.

Syntax

CELL(info_type,reference)

Info_type   is a text value that specifies what type of cell information you want. The following list shows the possible values of info_type and the corresponding results.

Info_type	Returns
"address"	Reference of the first cell in reference, as text.
"col"	Column number of the cell in reference.
"color"	1 if the cell is formatted in color for negative values; otherwise returns 0 (zero).
"contents"	Contents of the upper-left cell in reference. 
"filename"	Filename (including full path) of the file that contains reference, as text. Returns empty text ("") if the worksheet that contains reference has not yet been saved.
"format"	Text value corresponding to the number format of the cell. The text values for the various formats are shown in the following table. Returns "-" at the end of the text value if the cell is formatted in color for negative values. Returns "()" at the end of the text value if the cell is formatted with parentheses for positive or all values.
"parentheses"	1 if the cell is formatted with parentheses for positive or all values; otherwise returns 0.
"prefix"	Text value corresponding to the "label prefix" of the cell. Returns single quotation mark (') if the cell contains left-aligned text, double quotation mark (") if the cell contains right-aligned text, caret (^) if the cell contains centered text, backslash (\) if the cell contains fill-aligned text, and empty text ("") if the cell contains anything else. 
"protect"	0 if the cell is not locked, and 1 if the cell is locked.
"row"	Row number of the cell in reference. .
"type"	Text value corresponding to the type of data in the cell. Returns "b" for blank if the cell is empty, "l" for label if the cell contains a text constant, and "v" for value if the cell contains anything else.
"width"	Column width of the cell rounded off to an integer. Each unit of column width is equal to the width of one character in the default font size.

So, is that what you thought it did?

To get a row number of a reference you can also use
Code:
=ROW(reference)

or, if you want to find the row that contains "surname" use:
Code:
=MATCH("surname",A1:A99,0)

Cheers, Glenn.

Did you hear about the literalist show-jumper? He broke his nose jumping against the clock.
 
Thanks Glen,

I don't kow what row "surname" occurs on, so the match function works well.
I did have a look at Excel's help on the cell function, and used the row result. It just didn't give consistent results...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top