code to dynamically identify every nth value

kam2004

New Member
Joined
May 22, 2020
Messages
4
Office Version
  1. 2019
Platform
  1. Windows
  2. MacOS
Hello All

I have a list of 100000 numbers ordered in an ascending column
I am trying to write a formula to highlight (or just place 'yes' mark in an adjacent cell) every cell where the numerical value is x (the starting number in the ordered sequence) plus n (a value that could be changed).
So successive highlighted cells/rows are n higher than the last highlighted cell.

Please see the attached VBA code which I can make work until I try and rest the base value ("base1") from which I am trying to calculate the next n+12

Sub FindTP(InputValue, rng As Range)


Dim Cell As Range
Dim base1 As Integer
Dim TestValue As Integer

RunTP = "No"
base1 = InputValue

For Each Cell In rng

If Cell.Value > base1 + 12 Then

RunTP = "Yes"
base1 = Cell.Value

End If

Next Cell

End Function
End Sub



Any help to achieve this would be appreciated - the real number list to be analysed is 100000 long and so a laborious manual task otherwise.

Thanks in advance

KB
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Thinking out of the box a little, Assuming numbers in column A, starting in A2 (A1 needs to be empty or contain a text header for this to work).

In B2 and fill down, note that $C$2 represents the desired n value

=IF(A2=MAX(B$1:B1)+$C$2,A2,"No")

Then apply a custom format to column B, "Yes";"Yes";"Yes";@
 
Upvote 0
Hi & welcome to MrExcel.
How about
VBA Code:
Sub Kam()
   Dim Cl As Range
   Dim BaseNum As Long
   
   BaseNum = Range("A1").Value
   For Each Cl In Range("A1", Range("A" & Rows.Count).End(xlUp))
      If Cl.Value >= BaseNum + 12 Then
         Cl.Interior.Color = 45678
         BaseNum = BaseNum + 12
      End If
   Next Cell
End Sub
 
Upvote 0
Thanks for your help and speedy reply---i'll give it a try and report back shortly
Kam
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0
Cross posted Conditional format to highlight cell or row of every x+nth value in a ordered sequence

For future reference
While we do allow Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules). This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,732
Members
448,987
Latest member
marion_davis

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