Counting to the end of the array.

montecarlo2012

Well-known Member
Joined
Jan 26, 2011
Messages
984
Office Version
  1. 2010
Platform
  1. Windows
Hi everyone.
this code
VBA Code:
Sub jump()
    Dim i As Long, n As Long
    Dim f As Range

    For i = 2 To Range("B" & Rows.Count).End(3).Row
                               'target value ( 1 )
        Set f = Range("B" & i).Resize(, 5).Find(1, , xlValues, xlWhole)

        If Not f Is Nothing Then
              
            Range("K" & Rows.Count).End(xlUp).Offset(1, 0).Value = n

            n = -1
        End If

        n = n + 1
    Next

End Sub
is doing good to certain point.
because is counting the "Rows" where the target value " 1 " is not present
but, when arrived to the last location of number one then do not count anymore
so what I want is to count
also after the last one to the end of the array
I am loading a picture that maybe show you better the idea
1684891891724.png

as you see is perfect the count of 3,9 "0's if repeating" and 1
and the code stop right there,
I really need the last part count also, meaning in this case
must be 6 rows where number one is not present also.
Please any help.
Thank you for reading this.
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

Forum statistics

Threads
1,215,440
Messages
6,124,882
Members
449,193
Latest member
PurplePlop

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