开发者

Find name of the last cell with data in a row

开发者 https://www.devze.com 2023-04-04 08:42 出处:网络
I\'ve searched for an answer, but it seems that I can only find VBA-based solutions, which appear no longer be an option in Excel 2008.

I've searched for an answer, but it seems that I can only find VBA-based solutions, which appear no longer be an option in Excel 2008.

I'm trying to return the name of the last cell in a row that contains data. It looks like this:

+===========================================================+
                 A      /  B  /  C  /  D  /  E  (columns)
+===========================================================+
1     开发者_StackOverflow社区    || [Formula] /  3  /  4  /  5  / [blank]
2         || [Formula] /  7  /  8  / [blank] / [blank]
3         || [Formula] /  9  / 10 / 11 / 12
(rows)
+===========================================================+

and the end result would look like this:

+===========================================================+
             A   /  B  /  C  /  D  /  E  (columns)
+===========================================================+
1         || D1 /  3  /  4  /  5  / 
2         || C2 /  7  /  8  /     / 
3         || E3 /  9  / 10 / 11 / 12
(rows)
+===========================================================+


It looks like your data is sorted from left to right.
If it is, you could start with something like =MATCH(MAX(C4:K4);C4:K4) to retrieve the column index of the last cell (max) of the row. From there, it's easy to buid the address:
=ADDRESS(ROW();MATCH(MAX(C1:K1);C1:K1);4)


Edit: combining ADDRESS with COUNT or COUNTA (great idea from Dustin Geile) does not require the items to be sorted:

=ADDRESS(ROW();COLUMN()+COUNT(B1:Z1);4)


=CHAR(COUNTA(B1:ZZ1) + 65) & ROW()


You can try this arrayformula:

{=ADDRESS(ROW(B2),MAX(IF(ISEMPTY(B2:H2),0,COLUMN(B2:H2))))}

Validate with CtrlShiftEnter


If you are looking for the last cell with data, you can write a quick function and place it in a VBA module in your workbook.

Public Function LastCell(inRange as Range) LastCell = inRange.End(XlToRight).Address End Function

Or just omit the '.Address' if you want to get a range object pointing to the cell.

You can then use it in a formula like...

=LastCell(A1)

Regards Ray

0

精彩评论

暂无评论...
验证码 换一张
取 消