How do I populate unique cells from one worksheet to another based on a reference field?

edmund1985

New Member
Joined
Jun 24, 2016
Messages
3
Hi all,

I'm trying to come up with a formula that will populate unique cells in a new worksheet by referencing another worksheet that contains all the data.

So far I've used an INDEX MATCH formula, but that takes across all cells and displays the contents of the desired ones, while producing #N/A for the others.

Example

The data set looks something like this:

Unique IDColour
101White
102White
103Red
104White
105Red
106White

<tbody>
</tbody>

The formula I'm using is below:
=INDEX('Sheet1'!A2,MATCH("White",'Sheet1'!B2,0))

And the result in Sheet 2 looks like this:

Unique ID
101
102
#N/A
104
#N/A
106

<tbody>
</tbody>


I'd like if the '#N/A' cells weren't returned at all, i.e. for it to look like this:

Unique ID
101
102
104
106

<tbody>
</tbody>


Does anyone know if that's possible?? Thanks in advance for any help!!!
 

wideboydixon

Well-known Member
Joined
Jun 2, 2016
Messages
3,401
This seems to be a popular question; I see it many times per day :)

<b></b><table cellpadding="2.5px" rules="all" style=";background-color: #FFFFFF;border: 1px solid;border-collapse: collapse; border-color: #BBB"><colgroup><col width="25px" style="background-color: #DAE7F5" /><col /><col /><col /><col /><col /></colgroup><thead><tr style=" background-color: #DAE7F5;text-align: center;color: #161120"><th></th><th>A</th><th>B</th><th>C</th><th>D</th><th>E</th></tr></thead><tbody><tr ><td style="color: #161120;text-align: center;">1</td><td style="font-weight: bold;;">Unique ID</td><td style="font-weight: bold;;">Colour</td><td style="font-weight: bold;text-align: right;;"></td><td style="font-weight: bold;;">Unique ID</td><td style="font-weight: bold;;">Colour</td></tr><tr ><td style="color: #161120;text-align: center;">2</td><td style="text-align: right;;">101</td><td style=";">White</td><td style="text-align: right;;"></td><td style="text-align: right;;">101</td><td style=";">White</td></tr><tr ><td style="color: #161120;text-align: center;">3</td><td style="text-align: right;;">102</td><td style=";">White</td><td style="text-align: right;;"></td><td style="text-align: right;;">102</td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">4</td><td style="text-align: right;;">103</td><td style=";">Red</td><td style="text-align: right;;"></td><td style="text-align: right;;">104</td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">5</td><td style="text-align: right;;">104</td><td style=";">White</td><td style="text-align: right;;"></td><td style="text-align: right;;">106</td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">6</td><td style="text-align: right;;">105</td><td style=";">Red</td><td style="text-align: right;;"></td><td style=";"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">7</td><td style="text-align: right;;">106</td><td style=";">White</td><td style="text-align: right;;"></td><td style=";"></td><td style="text-align: right;;"></td></tr></tbody></table><p style="width:3.6em;font-weight:bold;margin:0;padding:0.2em 0.6em 0.2em 0.5em;border: 1px solid #BBB;border-top:none;text-align: center;background-color: #DAE7F5;color: #161120">Sheet1</p><br /><br /><table width="85%" cellpadding="2.5px" rules="all" style=";border: 2px solid black;border-collapse:collapse;padding: 0.4em;background-color: #FFFFFF" ><tr><td style="padding:6px" ><b>Array Formulas</b><table cellpadding="2.5px" width="100%" rules="all" style="border: 1px solid;text-align:center;background-color: #FFFFFF;border-collapse: collapse; border-color: #BBB"><thead><tr style=" background-color: #DAE7F5;color: #161120"><th width="10px">Cell</th><th style="text-align:left;padding-left:5px;">Formula</th></tr></thead><tbody><tr><th width="10px" style=" background-color: #DAE7F5;color: #161120">D2</th><td style="text-align:left">{=IFERROR(<font color="Blue">INDEX(<font color="Red">$A$2:$A$7,SMALL(<font color="Green">IF(<font color="Purple">$B$2:$B$7=$E$2,ROW(<font color="Teal">$B$2:$B$7</font>)-ROW(<font color="Teal">$B$1</font>)</font>),ROW(<font color="Purple"></font>)-1</font>)</font>), ""</font>)}</td></tr></tbody></table><b>Entered with Ctrl+Shift+Enter.</b> If entered correctly, Excel will surround with curly braces {}.
<b>Note: Do not try and enter the {} manually yourself</b></td></tr></table><br />

WBD
 

edmund1985

New Member
Joined
Jun 24, 2016
Messages
3
Hi WBD,

Thanks for taking a look at it. I tried using your formula but it's producing blank cells unfortunately... I removed the IFERROR function to get a better idea of what's happening and it's giving me #VALUE!

Is there another way of doing it?? Maybe with different formula combinations?

Thanks!
Ed
 

wideboydixon

Well-known Member
Joined
Jun 2, 2016
Messages
3,401
Well, you'll need to change the cell references etc.

{=IFERROR(INDEX($A$2:$A$7,SMALL(IF($B$2:$B$7=$E$2,ROW($B$2:$B$7)-ROW($B$1)),ROW()-1)), "")}

$A$2:$A$7 : Specifies all the values in the Unique ID column
$B$2:$B$7 : Specifies all the values in the Colour column
$E$2 : Specifies the cell that contains the criteria or you could hard-code this to "White"
$B$1 : Specifies the Colour header cell (i.e. the one that contains "Colour")
ROW()-1 : This is the tricky one. My first value was in D2 so this returns the values 1,2,3,4,5 etc. You might need to change this to return 1 in the first cell you put the formula

WBD
 

edmund1985

New Member
Joined
Jun 24, 2016
Messages
3
Hi WBD,

I actually got it to work perfectly with the simple example I gave :)

It's given me a few correct results for my actual dataset, although it's missed out certain records sequentially and then at random from various places in the column :(

I should mention that my actual dataset is over 7500 entries long, and the actual unique ID field values are more like:

412361863-1
412568432-1
412568432-2
412357123-1
420535415-1
420957135-1
420957135-2
420957135-3
412693515-1
etc.

<tbody>
</tbody>

Could that be affecting it??
 

Forum statistics

Threads
1,082,167
Messages
5,363,528
Members
400,747
Latest member
monty_gl

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top