Comparing the same sequence of numbers different from 0

Luthius

Active Member
Joined
Apr 5, 2011
Messages
324
I have in a row 14 numbers. 0-4.
I would like to indicate "xxx", in case of appear in this line 5 numbers in sequence that are <> of 0

Example:
0 0 0 0 1 1 3 1 1 0 0 0 0 0 "xxx"
0 0 1 0 0 1 2 3 4 0 1 1 0 0
0 1 1 2 1 1 0 0 0 0 1 1 0 0 "xxx"

Each number is on a cell and the result (xxx) in other.
A:N is my range

Luthius
 
=IF(0 < SUMPRODUCT(--(COUNTIF(OFFSET(A1:E1,0,COLUMN(A1:J1)-1),"<>0")=5)),"xxx","")

The key part is OFFSET(A1:E1,0,COLUMN(A1:J1)-1)

OFFSET(A1:E1,0,{0,1,2,3,...,9,10}) is an array of the 5 cell ranges A1:E1 - J1:N1

COUNTIF(OFFSET(...),"<>0") is an array of the non-zero count of those ranges.

COUNTIF(...)=5 is an array of TRUE,FALSE as to whether those ranges are all non-0

--(COUNTIF(...)=5) is that array converted to 1, 0

SUMPRODUCT(--(COUNTIF(...)-5)) sums all those 1 and 0

IF(SUMPRODUCT(...)>0, "xxx", """) is the answer
 
Upvote 0

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Code:
Function HasSequence(Str As String) As String
    Application.Volatile
    HasSequence = IIf(Str Like "*[1-9][1-9][1-9][1-9][1-9]*", "xxx", "")
End Function
 
Upvote 0
mikerickson

Thanks for your explanation, but I'm still afraid of you...:) Lol...



Sektor, very interesting your UDF. But, is there a way to change your solution in a Excel formula?
I liked your solution for the simplicity, and is there one way to change it to a formula?

Thanks
 
Upvote 0
IT IS FORMULA!!!
Type into cell B1: =HasSequence(A1)
And you'll see result!
 
Upvote 0
No Man, its an UDF. What I mean is native excel formula, in your code the solution was very simple, but I dont want to use VBA to solve the problem, only native formula from Excel.

Thanks
 
Upvote 0
Man, your solution is very very wonderful. I liked it so much, and I kept it in my library for the future, but as I loved it, I would like to translate your simplicity to an Excel formula.

Thanks
 
Upvote 0
I'm gonna tell you something. Yes, Excel's built-in formulas are much faster than UDFs. It's true. However, if you can't find solution with Excel's formulas, you have to resort to UDF. It's your only solution. If you have not so many such rows to process, better use UDF. Array formulas are good but they are memory-intensive 'cause all array calculations are carried in memory.
 
Upvote 0
I know what you wrote.
...

I was thinking something like

=SEARCH("*[1-9][1-9][1-9][1-9][1-9]*",MYSEQUENCE)

Or

=LOOKUP("*[1-9][1-9][1-9][1-9][1-9]*",A6:N6)

Use your criteria to get result.

What you think?
 
Upvote 0
It's useless 'cause you have several ranges with non-zero values like: 001234000110098756000.
The problem is that first non-zero range has four digits. Going further we get second range with two digits. Finally, we have third range which has five digits. Counting of non-zero digits is silly. Use UDF and forget it!
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,850
Members
452,948
Latest member
UsmanAli786

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