Find cells which are within 3 non-blank cells of another (with an offset)

ellison

Active Member
Joined
Aug 1, 2012
Messages
356
Office Version
  1. 365
Platform
  1. Windows
Hi, we are trying to find which cells in Column D are within 3 non-blank cells of entries in Column B, and mark them up in Column E.
... above and below of the entries in Col B

On the table, we've put Verdict in Col E.

In other words, we are trying to find...
- for the entries in Header-1
- where the next 3 non blank cells in the Info Column (D) are
- both above and below
- And mark those cells in the Verdict Column (E)

eg Cell E2 and E3 will not be marked because...
- the nearest entry in Header-1 is in cell B10
- and the nearest entries in Info Column D (so above cell D10) are D8, D6 and D4
- therefore cells E8, E6 and E4 are marked to be included in the Verdict Column (E)

I've tried searching for "next non-blank cells", "offsets" and all sorts but I'm going around in circles...

Wondered if somebody could take a look?

Thanks


mark-up-if-within-5-rows-above-or-below-which-are-NOT-blank.xlsm
ABCDE
1RowHeader-1Header-2InfoVerdict
22ALPHAInfo
33betaIs
44CharlieScatteredy
5557
6694Throughouty
77Delta 50
88EchoHerey
99 Foxtrot
1010GolfGolf
1111Hotel
1212India
1313One
1414TwoTwo
15151Withy
16162
17173Lotsy
1818Four
1919FiveOfy
2020Six
2121JulietBlanks
2222Kiloand
2323London
2424Mike
2525November
Sheet1 (2)
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
:confused: I have read through that several times and am still not sure I understand, but you can see if this meets the requirements.

23 10 22.xlsm
BDE
1Header-1InfoVerdict
2Info 
3Is 
4Scatteredy
5 
6Throughouty
7 
8Herey
9 
10Golf 
11 
12 
13 
14Two 
15Withy
16 
17Lotsy
18 
19Ofy
20 
21Blanks 
22and  
23 
24 
25 
Sheet5
Cell Formulas
RangeFormula
E2:E25E2=IF(AND(D2<>"",OR(IFNA(COUNTIF(D2:INDEX(D2:D$100,XMATCH("*",B2:B$100,2)),"?*")<=3,),IFNA(COUNTIF(D2:INDEX(D$2:D2,XMATCH("*",B$2:B2,2)),"?*")<=3,))),"y","")
 
Upvote 0
Hi Peter, huge thanks for looking into this Peter - and firstly apologies, I tried drafting & re-drafting that question but I totally get that it still looks "a bit vague" (understatement!).

I've looked into trying to use the formula but sorry to say that it's throwing up a couple of surprises if / when I change some of the entries around.

For example if I keep everything the same apart from change the entries in Header-1 to this, then I've got the following cells which I think would appear differently:

Book3
ABCDEF
1RowHeader-1Header-2InfoFormula
22ALPHAALPHAInfoyy
33betaIsyy
44CharlieCharlieScatteredyy
5557 
6694Throughout This should by "y" as it it is within 3 non blank Col-D-cells below row 4 where next entry is in Col B
77Delta 50 
88EchoHere This should by "y" as it it is within 3 non blank Col-D-cells below row 4 where next entry is in Col B
99 Foxtrot 
1010Golf 
1111Hotel 
1212India 
1313One 
1414Two 
15151With 
16162 
17173Lotsyy
1818Four 
1919FiveOfyy
2020Six 
2121JulietJulietBlanksyy
2222Kiloand  This should by "y" as it it is within 3 non blank cells below row 21 where next entry is in Col B
2323London 
2424Mike 
2525November 
1-orig
Cell Formulas
RangeFormula
E2:E25E2=IF(AND(D2<>"",OR(IFNA(COUNTIF(D2:INDEX(D2:D$100,XMATCH("*",B2:B$100,2)),"?*")<=3,),IFNA(COUNTIF(D2:INDEX(D$2:D2,XMATCH("*",B$2:B2,2)),"?*")<=3,))),"y","")


I'm wondering if I should break this problem down a bit more so that I can explain it more clearly?

Or I could try one more go using the above info if that may help?

- Our info is arranged in rows.
- And for the entries in Header-1 (Col-B), we are trying to find the next 3 non-blank cells in the info column above or below it. And mark those cells with a "y" in Column E (aka "Formula")
- So using the above example, cell B4 has entry (Charlie). The next 3 non-blank cells above it are D4, D3 and D2. So therefore (as your formula has done), the entries in cells E4, E3 and E2 are all "y".
- But...
- the next 3 non blank cells in Col D that are below row 4 are D4, D6 and D8. D4 is already being found by the formula. But D6 and D8 and not being picked up.

I hope this makes a bit more sense.

And huge thanks for persevering with this Peter (I've re-drafted this answer about a dozen times as well, so apologies for my delay in getting back to you!)

Warm Regards
 
Upvote 0
Oops, I forgot to tell the second XMATCH to look upwards instead of downwards. :oops:
See if this is better.

ellison.xlsm
BDE
2ALPHAInfoy
3Isy
4CharlieScatteredy
5 
6Throughouty
7 
8Herey
9 
10 
11 
12 
13 
14 
15With 
16 
17Lotsy
18 
19Ofy
20 
21JulietBlanksy
22and y
23 
24 
25 
Sheet2
Cell Formulas
RangeFormula
E2:E25E2=IF(AND(D2<>"",OR(IFNA(COUNTIF(D2:INDEX(D2:D$100,XMATCH("*",B2:B$100,2)),"?*")<=3,),IFNA(COUNTIF(D2:INDEX(D$2:D2,XMATCH("*",B$2:B2,2,-1)),"?*")<=3,))),"y","")
 
Upvote 0
Solution
Absolutely AMAZING - thank you so much for so much working on this, really appreciated!
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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