Last cell in a row and the one before

samahiji

Board Regular
Joined
Oct 6, 2015
Messages
82
Office Version
  1. 2019
Platform
  1. Windows
Hi

I have a function that return the last non-blank cell in row:

Code:
=LOOKUP(2,1/(A2:BD2<>""),A2:BD2)

I want now to return the 3 cells before it :confused: so at the end I have return the 4 last non-blank cells in the row!

Any one could help?
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
They're mixed between date and text.

Row\Col
A​
B​
C​
D​
E​
F​
G​
H​
I​
J​
K​
L​
M​
N​
1​
2​
3​
jon
7​
8​
danquo vadispaddydamon
0.2​
3​
4​
5​
last non-blank
0.2​
6​
last 4 non-blank valuesquo vadispaddydamon
0.2​

D5, just enter:
Rich (BB code):

=LOOKUP(9.99999999999999E+307,SEARCH("?",A2:BD2),A2:BD2)<strike></strike>
D6, control+shift+enter, not just enter, and copy across:
Rich (BB code):

=IFERROR(INDEX($A$2:$BD$2,
  SMALL(IF(COLUMN($A$2:$BD$2)-COLUMN($A$2)+1>=LARGE(IF(1-($A$2:$BD$2=""),
  COLUMN($A$2:$BD$2)-COLUMN($A$2)+1),MIN(4,COUNTIFS($A$2:$BD$2,"<>"))),
  IF(1-($A$2:$BD$2=""),COLUMN($A$2:$BD$2)-COLUMN($A$2)+1)),COLUMNS($D$6:D6))),"")
<strike></strike>
 
Upvote 0
Row\Col
A​
B​
C​
D​
E​
F​
G​
H​
I​
J​
K​
L​
M​
N​
1​
2​
3​
jon
7​
8​
danquo vadispaddydamon
0.2​
3​
4​
5​
last non-blank
0.2​
6​
last 4 non-blank valuesquo vadispaddydamon
0.2​

<tbody>
</tbody>


D5, just enter:
Rich (BB code):

=LOOKUP(9.99999999999999E+307,SEARCH("?",A2:BD2),A2:BD2)<strike></strike>
D6, control+shift+enter, not just enter, and copy across:
Rich (BB code):

=IFERROR(INDEX($A$2:$BD$2,
  SMALL(IF(COLUMN($A$2:$BD$2)-COLUMN($A$2)+1>=LARGE(IF(1-($A$2:$BD$2=""),
  COLUMN($A$2:$BD$2)-COLUMN($A$2)+1),MIN(4,COUNTIFS($A$2:$BD$2,"<>"))),
  IF(1-($A$2:$BD$2=""),COLUMN($A$2:$BD$2)-COLUMN($A$2)+1)),COLUMNS($D$6:D6))),"")
<strike></strike>


Aladin

It doesn't work for me!
I have XXX rows, then my index should be $A$2:$BD$XXX??

if have the table above in your post, then M1 should have the last value of row 1 (A1:L1), N1:P1 should contain the last 3 cells. And copy down.
 
Upvote 0
Aladin

It doesn't work for me!
I have XXX rows, then my index should be $A$2:$BD$XXX??

if have the table above in your post, then M1 should have the last value of row 1 (A1:L1), N1:P1 should contain the last 3 cells. And copy down.

Try to implement the sample and the formulas in a separate sheet to understand the set up...
 
Upvote 0
If it works for one row, it will certainly work for XXX rows. Try to adapt the set up.

Aladin

That's great!!!

I only changed the index from $A$2:$BD$2 to $A2:$BD2 and work perfect :)

It's really amazing function, I didn't understand it very well ;D
 
Upvote 0

Forum statistics

Threads
1,214,919
Messages
6,122,260
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top