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
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
mikerickson, your code will be incorrect here:
0 1 1 2 1 0 0 0 0 0 1 1 0 0

This is because non-zero numbers must be in sequence as Luthius asks.
 
Upvote 0
Code:
Option Explicit
Function NumStr(ByVal nString As String)
Dim i As Long, j As Long
Dim mString As String

j = 0
    For i = 1 To Len(nString)
        If Mid(nString, i, 1) > 0 Then
            If j< 5 Then mString = mString + Mid(nString, i, 1): j = j + 1
        Else
            If j< 5 Then mString = "": j = 0
        End If
    Next
    If j = 5 Then
        NumStr = "xxx"
    Else
        NumStr = ""
    End If
End Function
Excel Workbook
AB
100001131100000xxx
200100123401100
301121100001100xxx
Sheet1
Excel 2007
Cell Formulas
RangeFormula
B1=NumStr(A1)
B2=NumStr(A2)
B3=NumStr(A3)



Doh! Mis-read the question and the part about each number being in it's own Cell.
 
Last edited:
Upvote 0
Comfy,
Your code will be incorrect in case: 1111111111111111111 'cause in sequence there more than 5 non-zero digits (see post #3).
 
Upvote 0
Comfy,
Your code will be incorrect in case: 1111111111111111111 'cause in sequence there more than 5 non-zero digits (see post #3).

Lithius doesn't actually state what to do if there are 6 or more consecutive numbers. So 11111111111111 would match his initial criteria.
But my code is wrong in that it looks at a String, not separate columns.
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,843
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