Paste multiple lines from single point of reference

nickamongo

New Member
Joined
May 15, 2018
Messages
6
I want to copy multiple lines from one sheet that have the same reference number into another sheet, any ideas how? e.g. all the rows that have the ref: 123

[TABLE="class: grid, width: 50"]
<tbody>[TR]
[TD]Ref[/TD]
[TD]Info1[/TD]
[TD]Info2[/TD]
[TD]Info3[/TD]
[/TR]
[TR]
[TD]123
[/TD]
[TD]wer[/TD]
[TD]asd[/TD]
[TD]uio[/TD]
[/TR]
[TR]
[TD]456[/TD]
[TD]ert[/TD]
[TD]dfg[/TD]
[TD]wer[/TD]
[/TR]
[TR]
[TD]123[/TD]
[TD]xxy[/TD]
[TD]bbg[/TD]
[TD]yyhj[/TD]
[/TR]
[TR]
[TD]123[/TD]
[TD]wer[/TD]
[TD]asd[/TD]
[TD]ffg[/TD]
[/TR]
[TR]
[TD]456[/TD]
[TD]erg[/TD]
[TD]wer[/TD]
[TD]asd[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
any ideas how?

Hi, welcome to the forum!

Is it a one-off, or are you looking VBA or a dynamic formula or something else?

For a one-off try using an autofilter and copy and paste.
 
Upvote 0
Hi!

It's gong to be a recurring thing whereby it needs to return all rows (or specific data from all rows) with that ref. I am not great with VBA, l'll be honest..
 
Upvote 0
Here is a formula that you can try to adapt to your actual set-up. In this example, the ref you want to return the rows for is in cell B1 and cell B2 has a formula that is used to aid performance.


Excel 2013/2016
ABCD
1Ref123
2Helper cell3
3
4RefInfo1Info2Info3
5123werasduio
6123werasduio
7123werasduio
Sheet1
Cell Formulas
RangeFormula
A5=IF(ROWS(A$1:A1)>$B$2,"",INDEX(Sheet2!A$1:A$1000,AGGREGATE(15,6,(ROW(Sheet2!$A$1:$A$1000)-MIN(ROW(Sheet2!$A$1:$A$1000))+1)/(Sheet2!$A$1:$A$1000=$B$1),1)))




Excel 2013/2016
ABCD
1RefInfo1Info2Info3
2123werasduio
3456ertdfgwer
4123xxybbgyyhj
5123werasdffg
6456ergwerasd
Sheet2
 
Upvote 0
Great thanks! I'll give that a go. Just for my own peace of mind, can you explain the initial Argugment?

IF(ROWS(A$1:A1)>$B$2,

Not sure what the helper cell is or what the rows are looking at?



[TABLE="width: 85%"]
<tbody>[TR]
[TD]Worksheet Formulas[TABLE="width: 100%"]
<thead>[TR="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]
[TH="width: 10"]Cell[/TH]
[TH="align: left"]Formula[/TH]
[/TR]
</thead><tbody>[TR]
[TH="width: 10, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]A5[/TH]
[TD="align: left"]=IF(ROWS(A$1:A1)>$B$2,"",INDEX(Sheet2!A$1:A$1000,AGGREGATE(15,6,(ROW(Sheet2!$A$1:$A$1000)-MIN(ROW(Sheet2!$A$1:$A$1000))+1)/(Sheet2!$A$1:$A$1000=$B$1),1)))
[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
can you explain the initial Argugment?

Hi, these types of formula are generally quite resource hungry so we want to only perform their calculations when we have to.

The COUNTIFS() function in B2 tells us how many rows we need to retrieve for the reference of interest.

IF(ROWS(A$1:A1)>$B$2,

This compares the number of rows the formula has been copied down and only performs the expensive calculation when it's no more than the number of references we need to retrieve.
 
Upvote 0

Forum statistics

Threads
1,223,884
Messages
6,175,173
Members
452,615
Latest member
bogeys2birdies

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