# copy last 5 populated cells

#### redspanna

##### Well-known Member
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

### Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Are you asking for the contents of D1 to be a concatenation of those five cells? Are their contents text or numbers?

Last edited:
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

OK - does the list start in cell A1 or another cell? Will there be blanks in that range?

Yes always starts in A1 and NO blanks - I'm making this too easy for you

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)

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

Hang on a mo.

Last edited:
Try this (adapted for each cell in D):

=INDEX(A:A,COUNTA(A:A)-4,1)

ahh the sneaky COUNTA eh ?

Many thanks- that's great

Have a great new year

Replies
10
Views
864
Replies
7
Views
1K
Replies
5
Views
258
Replies
0
Views
611
Replies
3
Views
431

1,196,504
Messages
6,015,587
Members
441,903
Latest member
MG12345

### 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.

### Which adblocker are you using?

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

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