Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 116
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default 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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default 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
.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 116
Default highlight consecutive series of four numbers vba

Thank you very much,

I really appreciate your solution.

Again, with Thanks
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 116
Default 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
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Highlight Duplicate Rows (In Series) Rugby Stud Excel Programming 4 May 27th 09 07:58 PM
Calculating largest gap in a series of consecutive numbers Samuel Excel Worksheet Functions 6 March 29th 09 11:52 PM
Consecutive Numbers Antonio Excel Discussion (Misc queries) 11 March 13th 08 09:10 PM
consecutive numbers amyenoch Excel Programming 3 June 1st 05 05:12 PM
consecutive numbers Monique Excel Worksheet Functions 8 March 7th 05 05:09 AM


All times are GMT +1. The time now is 05:29 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"