Need help with Excel function

Avi11

New Member
Joined
Apr 6, 2018
Messages
4
First post here and a basic user of excel. Go easy on me.

I have a list of parts that were only available on certain dates (marked by 1 as available and 0 as not available in Sheet2). I have a separate table where I want to find out by part if they were available at least Y times in a X number of days.

Here is what I tried and getting #Value !:
=IF(COUNTIFS(Sheet2!$A$4:$A$8,"="&$A4,Sheet2!$B$3:$J$3,">="&B$3,Sheet2!$B$3:$J$3,"<="&B3+($D$1-1))>=$G$1,1,0)

where A is column for parts on both sheets
B3-J3 has dates on both sheets
D1 has the number of days (X)
G1 has the availability (Y)

Any help is appreciated.
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
COUNTIFS() requires that all ranges have the same number of rows and columns. A4:A8 is five rows by one column; B3:J3 is one row by nine columns. Would you please post a sample of your data—it's hard for me to reconstruct your worksheets just from the description.
 
Upvote 0
Here are the 2 sheets I described:


Book1
ABCDEFGHIJ
1X4Y2
2
31/15/20181/16/20181/17/20181/18/20181/19/20181/20/20181/21/20181/22/20181/23/2018
4ABC1245X#VALUE!
5SDHG3K3
6SJKFH23
7KJASFH22L
8LSDNF232
Sheet1
Cell Formulas
RangeFormula
B4=IF(COUNTIFS(Sheet2!$A$4:$A$8,"="&$A4,Sheet2!$B$3:$J$3,">="&B$3,Sheet2!$B$3:$J$3,"<="&B3+($D$1-1))>=$G$1,1,0)




Book1
ABCDEFGHIJ
31/15/20181/16/20181/17/20181/18/20181/19/20181/20/20181/21/20181/22/20181/23/2018
4ABC1245X010000101
5SDHG3K3010000010
6SJKFH23000001000
7KJASFH22L100010000
8LSDNF232100100001
Sheet2
 
Upvote 0
First post here and a basic user of excel. Go easy on me.

I have a list of parts that were only available on certain dates (marked by 1 as available and 0 as not available in Sheet2). I have a separate table where I want to find out by part if they were available at least Y times in a X number of days.

Here is what I tried and getting #Value !:
=IF(COUNTIFS(Sheet2!$A$4:$A$8,"="&$A4,Sheet2!$B$3:$J$3,">="&B$3,Sheet2!$B$3:$J$3,"<="&B3+($D$1-1))>=$G$1,1,0)

where A is column for parts on both sheets
B3-J3 has dates on both sheets
D1 has the number of days (X)
G1 has the availability (Y)

Any help is appreciated.

So I understand you want to know if the part was available at least 2 times, but I don't understand the number of days part. Do you mean was it available 2 times in a 4 day period?
 
Upvote 0
So I understand you want to know if the part was available at least 2 times, but I don't understand the number of days part. Do you mean was it available 2 times in a 4 day period?

Yes I would like to know if the part was available at least 2 times in a 4 day period.
 
Upvote 0
I'm sure this could be done with a formula, but it's eluding me at the moment. A UDF is straightforward, though:

[Table="width:, class:grid"][tr][td="bgcolor:#C0C0C0"][/td][td="bgcolor:#C0C0C0"]
A​
[/td][td="bgcolor:#C0C0C0"]
B​
[/td][td="bgcolor:#C0C0C0"]
C​
[/td][td="bgcolor:#C0C0C0"]
D​
[/td][td="bgcolor:#C0C0C0"]
E​
[/td][td="bgcolor:#C0C0C0"]
F​
[/td][td="bgcolor:#C0C0C0"]
G​
[/td][td="bgcolor:#C0C0C0"]
H​
[/td][td="bgcolor:#C0C0C0"]
I​
[/td][td="bgcolor:#C0C0C0"]
J​
[/td][td="bgcolor:#C0C0C0"]
K​
[/td][td="bgcolor:#C0C0C0"]
L​
[/td][/tr][tr][td="bgcolor:#C0C0C0"]
1​
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td="bgcolor:#F3F3F3"]
nTimes
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
2​
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td]
2​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
3​
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td="bgcolor:#F3F3F3"]
nDays
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
4​
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td]
4​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
5​
[/td][td="bgcolor:#F3F3F3"]
Item \ Day
[/td][td]
1​
[/td][td]
2​
[/td][td]
3​
[/td][td]
4​
[/td][td]
5​
[/td][td]
6​
[/td][td]
7​
[/td][td]
8​
[/td][td]
9​
[/td][td="bgcolor:#F3F3F3"]
[/td][td="bgcolor:#F3F3F3"]
[/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
6​
[/td][td]ABC1245X[/td][td]
1​
[/td][td]
0​
[/td][td]
1​
[/td][td]
0​
[/td][td]
1​
[/td][td]
0​
[/td][td]
0​
[/td][td]
1​
[/td][td]
1​
[/td][td="bgcolor:#CCFFCC"]
3​
[/td][td="bgcolor:#CCFFCC"]K6: =MinN(nTimes, nDays, B6:J6)[/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
7​
[/td][td]SDHG3K3[/td][td]
1​
[/td][td]
1​
[/td][td]
1​
[/td][td]
1​
[/td][td]
0​
[/td][td]
0​
[/td][td]
0​
[/td][td]
1​
[/td][td]
0​
[/td][td="bgcolor:#CCFFCC"]
3​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
8​
[/td][td]SJKFH23[/td][td]
0​
[/td][td]
0​
[/td][td]
0​
[/td][td]
1​
[/td][td]
1​
[/td][td]
0​
[/td][td]
1​
[/td][td]
1​
[/td][td]
0​
[/td][td="bgcolor:#CCFFCC"]
2​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
9​
[/td][td]KJASFH22L[/td][td]
0​
[/td][td]
0​
[/td][td]
0​
[/td][td]
0​
[/td][td]
1​
[/td][td]
0​
[/td][td]
0​
[/td][td]
1​
[/td][td]
0​
[/td][td="bgcolor:#CCFFCC"]
0​
[/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
10​
[/td][td]LSDNF232[/td][td]
1​
[/td][td]
0​
[/td][td]
1​
[/td][td]
0​
[/td][td]
0​
[/td][td]
1​
[/td][td]
1​
[/td][td]
1​
[/td][td]
0​
[/td][td="bgcolor:#CCFFCC"]
2​
[/td][td][/td][/tr]
[/table]


Code:
Function MinN(M As Long, N As Long, r As Range) As Long
  Dim avdInp        As Variant
  Dim nInp          As Long
  Dim i             As Long
  Dim k             As Long

  avdInp = r.Value
  nInp = UBound(avdInp, 2)

  For i = 1 To N
    k = k + avdInp(1, i)
  Next i
  If k >= M Then MinN = MinN + 1

  For i = i To nInp - N + 1
    k = k - avdInp(1, i - N) + avdInp(1, i)
    If k >= M Then MinN = MinN + 1
  Next i
End Function
 
Upvote 0

Forum statistics

Threads
1,223,958
Messages
6,175,633
Members
452,661
Latest member
Nonhle

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