Adding city names by rows

lelis

New Member
Joined
May 16, 2017
Messages
4
CityRisk LevelRisk LevelsDesired City 1City 2City 3City 4City 5
AboboExtremely Low RiskExtremely Low Risk3 AboboEndertaRaya Azebo
GodereVery High RiskVery Low Risk4 DimmaAbergeleMekele Special ZoneHintalo Wajirat
DimmaVery Low RiskLow Risk4 AdwaMereb LeheSamreLare
Gambela Low RiskModerate Risk5 Gambela ZuriaDegua TembienAlajeNaeder AdetWanthou
Gambela ZuriaModerate RiskHighly Moderate Risk2 GogEnticho
GogHighly Moderate RiskHigh Risk2 EndamehoniJor
JorHigh Risk Very High Risk1 Godere
AkoboExtremely Low Risk
JikawoVery Low Risk
LareLow Risk
WanthouModerate Risk
EndertaExtremely Low Risk
OflaVery High Risk
Hintalo WajiratVery Low Risk
SamreLow Risk
AlajeModerate Risk
AlamataHighly Moderate Risk
EndamehoniHigh Risk
Raya AzeboExtremely Low Risk
AbergeleVery Low Risk
AdwaLow Risk
Degua TembienModerate Risk
EntichoHighly Moderate Risk
Kola TembienHigh Risk
La'ilay MaychewVery High Risk
Mek'eleExtremely Low Risk
Mekele Special ZoneVery Low Risk
Mereb LeheLow Risk
Naeder AdetModerate Risk

<colgroup><col width="106" style="width:80pt"> <col width="161" style="width:121pt"> <col width="46" style="width:35pt"> <col width="160" style="width:120pt"> <col width="64" style="width:48pt"> <col width="106" style="width:80pt"> <col width="124" style="width:93pt"> <col width="147" style="width:110pt"> <col width="142" style="width:107pt"> <col width="64" style="width:48pt"> </colgroup><tbody>
</tbody>

Hi, I used this formula to get the desired cities randomly from the City column. However the cities desired increment by columns (horizontally) instead of by rows(Vertically). I want the cities to be added vertically. For ex:

Desired City 1

<tbody>
</tbody>
3 Adobo
Enderta
Raya Azebo

This is the formula I used: =IF(COLUMNS($F2:F2)>$E2,"",INDEX($A:$A,SMALL(IF($B$2:$B$30=$D2,IF(ISNA(MATCH($A$2:$A$30,$E2:E2,0)),ROW($B$2:$B$30),0),0),RANDBETWEEN(COUNTIF($B$2:$B$30,"<>"&$D2)+COLUMNS($F2:F2),ROWS($B$2:$B$30)))))

Please let me know if there is a way to do this.

Thank you very much in advance.
 

Some videos you may like

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

chleb

New Member
Joined
Apr 25, 2017
Messages
8
Hi,

I found some solution, but to understand it You should probably look into my sheet in Excel Online:
https://1drv.ms/x/s!AlDc4uNa3Ao8gypyQf0aeSpV7HwD

Here are the formulas used in the solution:

<b>Excel 2016 (Windows) 64 bit</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 /><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><th>F</th><th>G</th><th>H</th><th>I</th></tr></thead><tbody><tr ><td style="color: #161120;text-align: center;">1</td><td style=";">City</td><td style=";">Risk Level</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style=";">Risk Levels</td></tr><tr ><td style="color: #161120;text-align: center;">2</td><td style=";">Abobo</td><td style=";">Extremely Low Risk</td><td style="text-align: right;;"></td><td style="text-align: right;;">0.142876</td><td style="text-align: right;;"></td><td style=";">Risk level</td><td style=";">Very High Risk</td><td style="text-align: right;;"></td><td style=";">Extremely Low Risk</td></tr><tr ><td style="color: #161120;text-align: center;">3</td><td style=";">Godere</td><td style=";">Very High Risk</td><td style="text-align: right;;"></td><td style="text-align: right;;">0.406627</td><td style="text-align: right;;"></td><td style=";">Desired</td><td style="text-align: right;border-bottom: 1px solid black;;">5</td><td style="text-align: right;;"></td><td style=";">Very Low Risk</td></tr><tr ><td style="color: #161120;text-align: center;">4</td><td style=";">Dimma</td><td style=";">Very Low Risk</td><td style="text-align: right;;"></td><td style="text-align: right;;">0.634598</td><td style="text-align: right;;"></td><td style="border-right: 1px solid black;;">Cities</td><td style="border-top: 1px solid black;border-right: 1px solid black;border-left: 1px solid black;;">Ofla</td><td style="text-align: right;border-left: 1px solid black;;"></td><td style=";">Low Risk</td></tr><tr ><td style="color: #161120;text-align: center;">5</td><td style=";">Gambela</td><td style=";">Low Risk</td><td style="text-align: right;;"></td><td style="text-align: right;;">0.590462</td><td style="text-align: right;;"></td><td style="text-align: right;border-right: 1px solid black;;"></td><td style="border-right: 1px solid black;border-left: 1px solid black;;">Godere</td><td style="text-align: right;border-left: 1px solid black;;"></td><td style=";">Moderate Risk</td></tr><tr ><td style="color: #161120;text-align: center;">6</td><td style=";">Gambela Zuria</td><td style=";">Moderate Risk</td><td style="text-align: right;;"></td><td style="text-align: right;;">0.929963</td><td style="text-align: right;;"></td><td style="text-align: right;border-right: 1px solid black;;"></td><td style="border-right: 1px solid black;border-left: 1px solid black;;">La'ilay Maychew</td><td style="text-align: right;border-left: 1px solid black;;"></td><td style=";">Highly Moderate Risk</td></tr><tr ><td style="color: #161120;text-align: center;">7</td><td style=";">Gog</td><td style=";">Highly Moderate Risk</td><td style="text-align: right;;"></td><td style="text-align: right;;">0.828701</td><td style="text-align: right;;"></td><td style="text-align: right;border-right: 1px solid black;;"></td><td style="border-right: 1px solid black;border-left: 1px solid black;;"></td><td style="text-align: right;border-left: 1px solid black;;"></td><td style=";">High Risk</td></tr><tr ><td style="color: #161120;text-align: center;">8</td><td style=";">Jor</td><td style=";">High Risk</td><td style="text-align: right;;"></td><td style="text-align: right;;">0.12128</td><td style="text-align: right;;"></td><td style="text-align: right;border-right: 1px solid black;;"></td><td style="border-right: 1px solid black;border-bottom: 1px solid black;border-left: 1px solid black;;"></td><td style="text-align: right;border-left: 1px solid black;;"></td><td style=";">Very High Risk</td></tr><tr ><td style="color: #161120;text-align: center;">9</td><td style=";">Akobo</td><td style=";">Extremely Low Risk</td><td style="text-align: right;;"></td><td style="text-align: right;;">0.612942</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;border-top: 1px solid black;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">10</td><td style=";">Jikawo</td><td style=";">Very Low Risk</td><td style="text-align: right;;"></td><td style="text-align: right;;">0.984366</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">11</td><td style=";">Lare</td><td style=";">Low Risk</td><td style="text-align: right;;"></td><td style="text-align: right;;">0.632343</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">12</td><td style=";">Wanthou</td><td style=";">Moderate Risk</td><td style="text-align: right;;"></td><td style="text-align: right;;">0.662796</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">13</td><td style=";">Enderta</td><td style=";">Extremely Low Risk</td><td style="text-align: right;;"></td><td style="text-align: right;;">0.340894</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">14</td><td style=";">Ofla</td><td style=";">Very High Risk</td><td style="text-align: right;;"></td><td style="text-align: right;;">0.896094</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">15</td><td style=";">Hintalo Wajirat</td><td style=";">Very Low Risk</td><td style="text-align: right;;"></td><td style="text-align: right;;">0.793369</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">16</td><td style=";">Samre</td><td style=";">Low Risk</td><td style="text-align: right;;"></td><td style="text-align: right;;">0.4936</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">17</td><td style=";">Alaje</td><td style=";">Moderate Risk</td><td style="text-align: right;;"></td><td style="text-align: right;;">0.794289</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">18</td><td style=";">Alamata</td><td style=";">Highly Moderate Risk</td><td style="text-align: right;;"></td><td style="text-align: right;;">0.876628</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">19</td><td style=";">Endamehoni</td><td style=";">High Risk</td><td style="text-align: right;;"></td><td style="text-align: right;;">0.921099</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">20</td><td style=";">Raya Azebo</td><td style=";">Extremely Low Risk</td><td style="text-align: right;;"></td><td style="text-align: right;;">0.996822</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">21</td><td style=";">Abergele</td><td style=";">Very Low Risk</td><td style="text-align: right;;"></td><td style="text-align: right;;">0.02916</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">22</td><td style=";">Adwa</td><td style=";">Low Risk</td><td style="text-align: right;;"></td><td style="text-align: right;;">0.518003</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">23</td><td style=";">Degua Tembien</td><td style=";">Moderate Risk</td><td style="text-align: right;;"></td><td style="text-align: right;;">0.763648</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">24</td><td style=";">Enticho</td><td style=";">Highly Moderate Risk</td><td style="text-align: right;;"></td><td style="text-align: right;;">0.55265</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">25</td><td style=";">Kola Tembien</td><td style=";">High Risk</td><td style="text-align: right;;"></td><td style="text-align: right;;">0.881788</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">26</td><td style=";">La'ilay Maychew</td><td style=";">Very High Risk</td><td style="text-align: right;;"></td><td style="text-align: right;;">0.107096</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">27</td><td style=";">Mek'ele</td><td style=";">Extremely Low Risk</td><td style="text-align: right;;"></td><td style="text-align: right;;">0.420331</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">28</td><td style=";">Mekele Special Zone</td><td style=";">Very Low Risk</td><td style="text-align: right;;"></td><td style="text-align: right;;">0.372463</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">29</td><td style=";">Mereb Lehe</td><td style=";">Low Risk</td><td style="text-align: right;;"></td><td style="text-align: right;;">0.075304</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">30</td><td style=";">Naeder Adet</td><td style=";">Moderate Risk</td><td style="text-align: right;;"></td><td style="text-align: right;;">0.394132</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></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">Sheet3</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>Worksheet 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">=RAND(<font color="#0000FF"></font>)</td></tr></tbody></table></td></tr></table><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">G4</th><td style="text-align:left">{=IFERROR(<font color="#0000FF">IF(<font color="#FF0000">ROWS(<font color="#00FF00">$F$4:F4</font>)>$G$3,"",INDEX(<font color="#00FF00">$A$2:$A$30,MATCH(<font color="#800080">LARGE(<font color="#008080">(<font color="#FF00FF">$B$2:$B$30=$G$2</font>)*(<font color="#FF00FF">$D$2:$D$30</font>),ROWS(<font color="#FF00FF">$F$4:F4</font>)</font>),$D$2:$D$30,0</font>)</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 />

I hope this solves the problem.
Have a nice day.
 

Watch MrExcel Video

Forum statistics

Threads
1,127,199
Messages
5,623,331
Members
415,968
Latest member
Chabal74

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
Top