copy last 5 populated cells

redspanna

Well-known Member
Joined
Jul 27, 2005
Messages
1,602
Office Version
  1. 365
Platform
  1. Windows
Can I please have help to get code to carry out simple task below

Find last populated cell through Column A of Sheet1

From that cell select the next 5 cells UP for both columns A and B and copy that data into cell D1

So if A50 is the last populated cell, the code would copy A45:B50 into D1

Many thanks in advance
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Are you asking for the contents of D1 to be a concatenation of those five cells? Are their contents text or numbers?
 
Last edited:
Upvote 0
Nope, just want the copied data pasted using D1 as the start point, so in example above A45:B50 would be copied and pasted into D1:E5
Yes, contents and text and numbers

thanks
 
Upvote 0
OK - does the list start in cell A1 or another cell? Will there be blanks in that range?
 
Upvote 0
Yes always starts in A1 and NO blanks - I'm making this too easy for you ;)
 
Upvote 0
Yes, you are! If these are numbers, try this:


Excel 2016 (Windows) 32 bit
ABCDE
110010087100
287877087
390908590
485856985
510010090100
69090
7100100
887100
97087
108590
116985
1290100
Sheet2
Cell Formulas
RangeFormula
D1=INDEX(A:A,COUNT(A:A)-4,1)
D2=INDEX(A:A,COUNT(A:A)-3,1)
D3=INDEX(A:A,COUNT(A:A)-2,1)
D4=INDEX(A:A,COUNT(A:A)-1,1)
D5=INDEX(A:A,COUNT(A:A),1)
E1=INDEX(B:B,COUNT(B:B)-4,1)
E2=INDEX(B:B,COUNT(B:B)-3,1)
E3=INDEX(B:B,COUNT(B:B)-2,1)
E4=INDEX(B:B,COUNT(B:B)-1,1)
E5=INDEX(B:B,COUNT(B:B),1)
 
Upvote 0
Ok, As Column A will be mixture of text and numbers, example Apple 123 the formula
Code:
=INDEX(A:A,COUNT(A:A)-4,1)
gives a #VALUE! error

However column B holds numbers only so the formula
Code:
=INDEX(B:B,COUNT(B:B)-4,1)
works fine
 
Upvote 0
ahh the sneaky COUNTA eh ?

Many thanks- that's great

Have a great new year :)
 
Upvote 0

Forum statistics

Threads
1,213,527
Messages
6,114,140
Members
448,551
Latest member
Sienna de Souza

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