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:

ABCD
sdsadsadasdfdsfsubnet
dfsdfsddfdssadfasgateway
dfsdfdsfsdfdsfsdsdfsf
dfsdfdsfsdfdsfssubnet
sdfgssdgdhsdgsdfdfgfdgh
dgsfdgfdsfsddsfsdgdgfdg
fsfgfgdfgfdsdgsrrgateway
hfdhggfsfgfddfgsdfgsubnet
gsdfgfsdfsdfgsdgdgateway

<tbody>
</tbody>



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:

ABCDE
sdsadsadasdfdsfsubnetdfsdfsd
dfsdfsddfdssadfasgateway
dfsdfdsfsdfdsfsdsdfsf
dfsdfdsfsdfdsfssubnetfsfgf
sdfgssdgdhsdgsdfdfgfdgh
dgsfdgfdsfsddsfsdgdgfdg
fsfgfgdfgfdsdgsrrgateway
hfdhggfsfgfddfgsdfgsubnetgsdfgf
gsdfgfsdfsdfgsdgdgateway

<tbody>
</tbody>


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! :) Thanks everyone!

-Andrew
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.

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
1sdsadsadasdfdsfsubnetdfsdfsd
2dfsdfsddfdssadfasgateway
3dfsdfdsfsdfdsfsdsdfsf
4dfsdfdsfsdfdsfssubnetfsfgf
5sdfgssdgdhsdgsdfdfgfdgh
6dgsfdgfdsfsddsfsdgdgfdg
7fsfgfgdfgfdsdgsrrgateway
8hfdhggfsfgfddfgsdfgsubnetgsdfgf
9gsdfgfsdfsdfgsdgdgateway

<colgroup><col style="width: 25pxpx"><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet1

Array Formulas
CellFormula
E1{=IF($D1="subnet",INDEX($A2:$A$9,MIN(IF($D2:$D$9="gateway",ROW($D2:$D$9)-ROW($D2)+1))),"")}

<thead>
</thead><tbody>
</tbody>
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself

<tbody>
</tbody>



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,214,976
Messages
6,122,541
Members
449,089
Latest member
davidcom

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