VBA Modification

Usercode

Board Regular
Joined
Aug 18, 2017
Messages
107
Office Version
  1. 2016
Platform
  1. Windows
Hi everybody,

I have this VBA code which works on the data starting from Row2 of worksheet. Instead of Row2, I want it to start from row5. I tried to change it a little but I was not successful. How can i do this? please. thanks.

Code:
Sub Intervals()    Dim R As Range, C As Range
    With Cells(1).CurrentRegion
        With .Offset(1).Resize(.Rows.Count - 1)
            For Each R In .Cells
                Set C = .Find(R.Value, R, , 1, , , 2)
                If (C.Address <> R.Address) * (C.Row > R.Row) Then
                    R.Offset(, 7) = C.Row - R.Row - 1
                Else
                    R.Offset(, 7) = "na"
                End If
            Next
        End With
    End With
End Sub
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
MickG, I tried it but it didn't work. It gives Run time error 1004.
 
Upvote 0
Yes, row1-row4 are blanks. i want to keep them blank.
 
Upvote 0
Try this:-
Code:
[COLOR="Navy"]Sub[/COLOR] MG02Feb37
[COLOR="Navy"]Dim[/COLOR] R as range, c [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]With[/COLOR] Range("A5").CurrentRegion
       MsgBox .Cells.Address '[COLOR="Green"][B]Just to show you the Address of Currentregion.!![/B][/COLOR]
            [COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] R [COLOR="Navy"]In[/COLOR] .Cells
                [COLOR="Navy"]Set[/COLOR] c = .Find(R.Value, R, , 1, , , 2)
                [COLOR="Navy"]If[/COLOR] (c.Address <> R.Address) * (c.Row > R.Row) [COLOR="Navy"]Then[/COLOR]
                    R.Offset(, 7) = c.Row - R.Row - 1
                [COLOR="Navy"]Else[/COLOR]
                    R.Offset(, 7) = "na"
                [COLOR="Navy"]End[/COLOR] If
            [COLOR="Navy"]Next[/COLOR]
       [COLOR="Navy"]End[/COLOR] [COLOR="Navy"]With[/COLOR]
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0

Forum statistics

Threads
1,215,943
Messages
6,127,820
Members
449,409
Latest member
katiecolorado

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