Using SUMPRODUCT and ISNUMBER to find if an array of number has a number included with special conditions

Lekazard

New Member
Joined
May 25, 2023
Messages
11
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
I'm banging my head with this issue and help would be highly appreciated.
I have some data gathered monthly and to sum it up I need to discover if midweek holidays are included within a range of dates. For simplicity the relevant data on the sheet is structured like this:
D: Dates I'm comparingH: Date rangeI: Expected output values
4453644531; 44532; 44533; 44537; 44538; 44539; 44540FALSE
4455644531; 44532; 44533; 44537; 44538; 44539; 44540; 44550; 44551; 44552; 44553FALSE
4455944531; 44532; 44533; 44537; 44538; 44539; 44540; 44550; 44551; 44552; 44553; 44557; 44558; 44559; 44560; 44561TRUE

What I want to know is does the the array listed in column H have any of the numbers listed in column D with the special rule there must be one consecutive datevalue before and 2 after (to simplify, if the number we are comparing is 2, then an array of 1, 2, 3, 4 would give TRUE).
The two formulas I've tried to use in column I are:
=IF(AND(ISNUMBER(MATCH(D2-1; $H$2:$H$1000; 0)); OR(ISNUMBER(MATCH(D2+2; $H$2:$H$1000; 0)); ISNUMBER(MATCH(D2+3; $H$2:$H$1000; 0)))); TRUE; FALSE)
and
=IF(SUMPRODUCT(--(ISNUMBER(MATCH(D2:D1000-1; $H$2:$H$1000; 0))); --(ISNUMBER(MATCH(D2:D1000+2; $H$2:$H$1000; 0))); --(ISNUMBER(MATCH(D2:D1000+3; $H$2:$H$1000; 0)))) > 0; TRUE; FALSE)
but both give FAIL for every row meaning, that they are not compiled right. Because of localization I use semicolon as the separator inside formulas. Could anyone help me out with this one because my head is really starting to hurt.
 
Ok what does this return
Excel Formula:
=SUM(--(CODE(MID(H4,SEQUENCE(LEN(H4)),1))>59))
Change the H4 to a cell that should return true.
 
Upvote 0

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Ok what does this return
Excel Formula:
=SUM(--(CODE(MID(H4,SEQUENCE(LEN(H4)),1))>59))
Change the H4 to a cell that should return true.
I pasted it into I4 and then used the Fill Handle for every row. For every row it returns 0
 
Upvote 0
In that case I'm not sure why it's not working for you, I though you might have some non-breakin spaces, but obviously not.
As can be seen in both posts#3 & 4 those suggestions work for us.
Can you copy the data we posted into a blank sheet, change the commas to semi-colons & see if that works.
To copy the data use the copy icon

Copy icon.png
 
Upvote 0
I'm guessing that if the previous suggestions have not worked for you then this probably won't either, but this is how I would attempt it.

Lekazard.xlsm
DHI
1
24453644531; 44532; 44533; 44537; 44538; 44539; 44540FALSE
34455644531; 44532; 44533; 44537; 44538; 44539; 44540; 44550; 44551; 44552; 44553FALSE
44455944531; 44532; 44533; 44537; 44538; 44539; 44540; 44550; 44551; 44552; 44553; 44557; 44558; 44559; 44560; 44561TRUE
Sheet1
Cell Formulas
RangeFormula
I2:I4I2=ISNUMBER(FIND(TEXTJOIN("; ",,SEQUENCE(4,,D2-1)),H2))
 
Upvote 0
Is it possible to upload sample file in some website and give link here.

Here's the data and some of the formulas I've been trying. The layout of the sheets is pretty awful but hopefully it's readable. Also last thing I tried was VBA, but couldn't get the out come with that method either.

VBA Code:
Sub CheckConsecutiveAndSecondPosition()
    Dim arr() As String
    Dim rngD As Range
    Dim cellD As Range
    Dim i As Long
    Dim matchCount As Integer
    
    ' Get the values in column D
    Set rngD = Range("D2:D" & Cells(Rows.Count, "D").End(xlUp).Row)
    
    ' Clean and split the array in cell H14 by semicolon
    arr = Split(Replace(Trim(Range("H14").Value), ";", " "), " ")
    
    ' Initialize match count
    matchCount = 0
    
    ' Check if any number in column D matches the conditions
    For Each cellD In rngD
        If IsNumeric(cellD.Value) Then
            For i = 0 To UBound(arr) - 3
                If CLng(Val(arr(i))) = cellD.Value And _
                    IsNumeric(arr(i + 1)) And CLng(Val(arr(i + 1))) = cellD.Value - 1 And _
                    IsNumeric(arr(i + 2)) And CLng(Val(arr(i + 2))) = cellD.Value + 1 And _
                    IsNumeric(arr(i + 3)) And CLng(Val(arr(i + 3))) = cellD.Value + 2 Then
                    matchCount = matchCount + 1
                    Exit For
                End If
            Next i
        End If
    Next cellD
    
    ' Set the boolean output based on the match count
    Range("I14").Value = (matchCount > 0)
End Sub
 
Upvote 0
I didn't understand the requirement before. I think that I do now. How is this?

23 06 03.xlsm
DHI
1Holidays44560; 44561FALSE
24455844560; 44561FALSE
34453644557; 44558; 44559; 44560; 44561TRUE
44455644557; 44558; 44559; 44560; 44561TRUE
54455944557; 44558FALSE
644560; 44561FALSE
744553FALSE
844561FALSE
944559; 44560; 44561FALSE
1044531; 44532; 44533; 44537; 44538; 44539; 44540; 44550; 44551; 44552; 44553; 44557; 44558; 44559; 44560; 44561TRUE
Check sequence
Cell Formulas
RangeFormula
I1:I10I1=OR(BYROW(D$2:D$5,LAMBDA(rw,ISNUMBER(FIND(TEXTJOIN("; ",,SEQUENCE(4,,rw-1)),H1)))))
 
Upvote 1
Solution
I didn't understand the requirement before. I think that I do now. How is this?

23 06 03.xlsm
DHI
1Holidays44560; 44561FALSE
24455844560; 44561FALSE
34453644557; 44558; 44559; 44560; 44561TRUE
44455644557; 44558; 44559; 44560; 44561TRUE
54455944557; 44558FALSE
644560; 44561FALSE
744553FALSE
844561FALSE
944559; 44560; 44561FALSE
1044531; 44532; 44533; 44537; 44538; 44539; 44540; 44550; 44551; 44552; 44553; 44557; 44558; 44559; 44560; 44561TRUE
Check sequence
Cell Formulas
RangeFormula
I1:I10I1=OR(BYROW(D$2:D$5,LAMBDA(rw,ISNUMBER(FIND(TEXTJOIN("; ",,SEQUENCE(4,,rw-1)),H1)))))

I copy-pasted this formula into my sheet, and this is the first formula which gave me the expected output! It works! Still gotta do some testing on Monday and I have couple of more conditions I need to apply and take under consideration, but this was by far the hardest part of this task and now after being stuck for over a week I can now proceed further.

Big thanks for everyone giving a helping hand, can't state how much I appreciate this!
 

Attachments

  • Näyttökuva (8).png
    Näyttökuva (8).png
    175.1 KB · Views: 7
Upvote 0
You're welcome. Glad we could help. Thanks for the follow-up. :)
 
Upvote 1

Forum statistics

Threads
1,223,977
Messages
6,175,753
Members
452,667
Latest member
vanessavalentino83

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