ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   highlight consecutive series of four numbers vba (https://www.excelbanter.com/excel-programming/435642-highlight-consecutive-series-four-numbers-vba.html)

smandula

highlight consecutive series of four numbers vba
 
I would like to highlight all four consecutive sequential
numbers in range of C2:V25

1 2 3 4 11 23 36 42
25 26 33 34 35 36 40 45

1 2 3 4 and 33 34 35 36 will be highlighted only
any color.

With Thanks

JLGWhiz[_2_]

highlight consecutive series of four numbers vba
 
See if this will do it. This assumes that the sequence is horizontal in
rows rather than in columns.

Sub fh()
Dim c As Range
x = 1
For Each c In Range("C2:V25")
If c.Offset(, 1).Value - c.Value = 1 Then
If x = 1 Then
rng = c.Address
End If
x = x + 1
If x = 4 Then
Range(rng, c.Offset(, 1)).Interior.ColorIndex = 6
x = 1
End If
Else
x = 1
End If
Next
End Sub



"smandula" wrote in message
...
I would like to highlight all four consecutive sequential
numbers in range of C2:V25

1 2 3 4 11 23 36 42
25 26 33 34 35 36 40 45

1 2 3 4 and 33 34 35 36 will be highlighted only
any color.

With Thanks




Mike H

highlight consecutive series of four numbers vba
 
Hi,

Will any of the ranges overlap e.g. 6 (or more) consecutive numbers

123456

will any consecutive numbers wrap around 2 rows i.e. the last 2 rows on 1
line and the first 2 on the next be a consecutive series?

Mike

"smandula" wrote:

I would like to highlight all four consecutive sequential
numbers in range of C2:V25

1 2 3 4 11 23 36 42
25 26 33 34 35 36 40 45

1 2 3 4 and 33 34 35 36 will be highlighted only
any color.

With Thanks
.


smandula

highlight consecutive series of four numbers vba
 
Thank you very much,

I really appreciate your solution.

Again, with Thanks

smandula

highlight consecutive series of four numbers vba
 
Thanks for replying.

There will be no wrap, just straight 4 consecutive numbers.

The solution provided works extremely well!

I tried individual if statements, but the colors and
numbers splattered all over the given range. This solution
cuts only the required 4 consecutive cells

Thanks to everyone providing and reading this post


All times are GMT +1. The time now is 03:02 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com