Formula to find next instance of a word in a specific column?

AGrayson84

New Member
Joined
Mar 21, 2017
Messages
18
Hi everyone, I was hoping someone may be able to assist me with an unusual request that I have not been able to find a formula for that I have been able to modify successfully. I have a worksheet that contains the many instances of the word "Subnet" within column "D". For each instance of "Subnet" in column D, there is one instance of the word "Gateway" in column D of a below row. Below is a very rough example:

[TABLE="width: 500"]
<tbody>[TR]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[/TR]
[TR]
[TD]sdsad[/TD]
[TD]sadas[/TD]
[TD]dfdsf[/TD]
[TD]subnet[/TD]
[/TR]
[TR]
[TD]dfsdfsd[/TD]
[TD]dfds[/TD]
[TD]sadfas[/TD]
[TD]gateway[/TD]
[/TR]
[TR]
[TD]dfsdf[/TD]
[TD]dsfsdf[/TD]
[TD]dsfsd[/TD]
[TD]sdfsf[/TD]
[/TR]
[TR]
[TD]dfsdf[/TD]
[TD]dsfsdf[/TD]
[TD]dsfs[/TD]
[TD]subnet
[/TD]
[/TR]
[TR]
[TD]sdfgs[/TD]
[TD]sdgdh[/TD]
[TD]sdgsdf[/TD]
[TD]dfgfdgh[/TD]
[/TR]
[TR]
[TD]dgsfdgfd[/TD]
[TD]sfsd[/TD]
[TD]dsfsdg[/TD]
[TD]dgfdg[/TD]
[/TR]
[TR]
[TD]fsfgf[/TD]
[TD]gdfgfd[/TD]
[TD]sdgsrr[/TD]
[TD]gateway[/TD]
[/TR]
[TR]
[TD]hfdhggf[/TD]
[TD]sfgfd[/TD]
[TD]dfgsdfg[/TD]
[TD]subnet[/TD]
[/TR]
[TR]
[TD]gsdfgf[/TD]
[TD]sdfsd[/TD]
[TD]fgsdgd[/TD]
[TD]gateway[/TD]
[/TR]
</tbody>[/TABLE]



What I would like to do is have a formula that I can use in column E of each row where "subnet" is in column D, and I would like that formula to find the next instance of "gateway" in column D (it's not always in the very-next row), then write the value of column A of that same row (the "gateway" row) into column E of the subnet row. For instance:

[TABLE="width: 500"]
<tbody>[TR]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[TD]E[/TD]
[/TR]
[TR]
[TD]sdsad[/TD]
[TD]sadas[/TD]
[TD]dfdsf[/TD]
[TD]subnet[/TD]
[TD]dfsdfsd[/TD]
[/TR]
[TR]
[TD]dfsdfsd[/TD]
[TD]dfds[/TD]
[TD]sadfas[/TD]
[TD]gateway[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]dfsdf[/TD]
[TD]dsfsdf[/TD]
[TD]dsfsd[/TD]
[TD]sdfsf[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]dfsdf[/TD]
[TD]dsfsdf[/TD]
[TD]dsfs[/TD]
[TD]subnet[/TD]
[TD]fsfgf[/TD]
[/TR]
[TR]
[TD]sdfgs[/TD]
[TD]sdgdh[/TD]
[TD]sdgsdf[/TD]
[TD]dfgfdgh[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]dgsfdgfd[/TD]
[TD]sfsd[/TD]
[TD]dsfsdg[/TD]
[TD]dgfdg[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]fsfgf[/TD]
[TD]gdfgfd[/TD]
[TD]sdgsrr[/TD]
[TD]gateway[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]hfdhggf[/TD]
[TD]sfgfd[/TD]
[TD]dfgsdfg[/TD]
[TD]subnet[/TD]
[TD]gsdfgf[/TD]
[/TR]
[TR]
[TD]gsdfgf[/TD]
[TD]sdfsd[/TD]
[TD]fgsdgd[/TD]
[TD]gateway[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]


I believe I do have a VBA Script I am using for something else, that I can easily modify to use for placing the formula for each cell in column "E" where the word "subnet" is found in Column "D". However, Macros are disabled on most of our workstations on the specific domain that this spreadsheet is on, so if there is a way to do it without macro that would be great. But I primarily need just the formula for finding the value of the next instance of the cell in column A, where "gateway" is found in column D of the same row.

Hopefully that's not too confusing and if anyone needs to me to elaborate on anything please let me know. Any help on this would be hugely appreciated! :smile: Thanks everyone!

-Andrew
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

Book1
ABCDE
1sdsadsadasdfdsfsubnetdfsdfsd
2dfsdfsddfdssadfasgateway
3dfsdfdsfsdfdsfsdsdfsf
4dfsdfdsfsdfdsfssubnetfsfgf
5sdfgssdgdhsdgsdfdfgfdgh
6dgsfdgfdsfsddsfsdgdgfdg
7fsfgfgdfgfdsdgsrrgateway
8hfdhggfsfgfddfgsdfgsubnetgsdfgf
9gsdfgfsdfsdfgsdgdgateway
Sheet1
Cell Formulas
RangeFormula
E1{=IF($D1="subnet",INDEX($A2:$A$9,MIN(IF($D2:$D$9="gateway",ROW($D2:$D$9)-ROW($D2)+1))),"")}
Press CTRL+SHIFT+ENTER to enter array formulas.


WBD
 
Upvote 0
Thank you both so much for the help!!!!!!!!!!!!!!



ABCDE
sdsadsadasdfdsfsubnetdfsdfsd
dfsdfsddfdssadfasgateway
dfsdfdsfsdfdsfsdsdfsf
dfsdfdsfsdfdsfssubnetfsfgf
sdfgssdgdhsdgsdfdfgfdgh
dgsfdgfdsfsddsfsdgdgfdg
fsfgfgdfgfdsdgsrrgateway
hfdhggfsfgfddfgsdfgsubnetgsdfgf
gsdfgfsdfsdfgsdgdgateway

<colgroup><col style="width: 25pxpx"><col><col><col><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]1[/TD]

[TD="align: center"]2[/TD]

[TD="align: center"]3[/TD]

[TD="align: center"]4[/TD]

[TD="align: center"]5[/TD]

[TD="align: center"]6[/TD]

[TD="align: center"]7[/TD]

[TD="align: center"]8[/TD]

[TD="align: center"]9[/TD]

</tbody>
Sheet1

[TABLE="width: 85%"]
<tbody>[TR]
[TD]Array 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: 10px"]Cell[/TH]
[TH="align: left"]Formula[/TH]
[/TR]
</thead><tbody>[TR]
[TH="width: 10px, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]E1[/TH]
[TD="align: left"]{=IF($D1="subnet",INDEX($A2:$A$9,MIN(IF($D2:$D$9="gateway",ROW($D2:$D$9)-ROW($D2)+1))),"")}[/TD]
[/TR]
</tbody>[/TABLE]
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself
[/TD]
[/TR]
</tbody>[/TABLE]



WBD

Thank you WBD! I did try this and did the CTRL + SHIFT + ENTER method. It did populate the brackets for me when I did that, but the cell I entered it in had no data. Might have been something on my part that caused it not to work though!



Or

E1 copied down
=IF(D1="subnet",INDEX(A1:$A$1000,MATCH("gateway",D1:$D$1000,0)),"")

M.


Thanks M! I wasn't hoping to fill a formula in all cells of column D to make this work, but surely it was probably the only option to do it without macros, so I made a new column for this formula anyway and it happened to work out just fine :)




Thanks again to both of you!!!!!

-Andrew
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,265
Members
452,627
Latest member
KitkatToby

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