Mark consecutive Non-Blank Cells

rit_netsys

New Member
Joined
Jan 13, 2016
Messages
8
Hello,
I need to mark consecutive more than 5 Non-Blank cells in excel like given below. It will be good if this can be done in VBA Macro.

ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACAD
2534333433233333334444
12345657788765434666
23456778676768666666

<tbody>
</tbody>

Need help to achieve this.
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Try this, for data starting row 1 :-
Code:
[COLOR=navy]Sub[/COLOR] MG10Apr06
[COLOR=navy]Dim[/COLOR] Rng [COLOR=navy]As[/COLOR] Range, Dn [COLOR=navy]As[/COLOR] Range, R [COLOR=navy]As[/COLOR] Range
[COLOR=navy]Dim[/COLOR] Lst [COLOR=navy]As[/COLOR] [COLOR=navy]Long[/COLOR]
[COLOR=navy]Set[/COLOR] Rng = Range("A1", Range("A" & Rows.Count).End(xlUp))
    [COLOR=navy]For[/COLOR] [COLOR=navy]Each[/COLOR] Dn [COLOR=navy]In[/COLOR] Rng
        Lst = Cells(Dn.Row, Columns.Count).End(xlToLeft).Column
            [COLOR=navy]For[/COLOR] [COLOR=navy]Each[/COLOR] R [COLOR=navy]In[/COLOR] Dn.Resize(, Lst).SpecialCells(xlCellTypeConstants).Areas
                [COLOR=navy]If[/COLOR] R.Count > 5 [COLOR=navy]Then[/COLOR] R.Font.Color = vbRed
            [COLOR=navy]Next[/COLOR] R
    [COLOR=navy]Next[/COLOR] Dn
[COLOR=navy]End[/COLOR] [COLOR=navy]Sub[/COLOR]
Regards Mick
 
Last edited:
Upvote 0
How about
Code:
Sub FlagCells()
   Dim Rng As Range
   Dim i As Long
   For i = 1 To ActiveSheet.UsedRange.Rows.Count
      For Each Rng In Rows(i).SpecialCells(xlConstants).Areas
         If Rng.Count > 5 Then Rng.Font.Color = vbRed
      Next Rng
   Next i
End Sub
 
Upvote 0
Many thanks.. Its working fine

Try this, for data starting row 1 :-
Code:
[COLOR=navy]Sub[/COLOR] MG10Apr06
[COLOR=navy]Dim[/COLOR] Rng [COLOR=navy]As[/COLOR] Range, Dn [COLOR=navy]As[/COLOR] Range, R [COLOR=navy]As[/COLOR] Range
[COLOR=navy]Dim[/COLOR] Lst [COLOR=navy]As[/COLOR] [COLOR=navy]Long[/COLOR]
[COLOR=navy]Set[/COLOR] Rng = Range("A1", Range("A" & Rows.Count).End(xlUp))
    [COLOR=navy]For[/COLOR] [COLOR=navy]Each[/COLOR] Dn [COLOR=navy]In[/COLOR] Rng
        Lst = Cells(Dn.Row, Columns.Count).End(xlToLeft).Column
            [COLOR=navy]For[/COLOR] [COLOR=navy]Each[/COLOR] R [COLOR=navy]In[/COLOR] Dn.Resize(, Lst).SpecialCells(xlCellTypeConstants).Areas
                [COLOR=navy]If[/COLOR] R.Count > 5 [COLOR=navy]Then[/COLOR] R.Font.Color = vbRed
            [COLOR=navy]Next[/COLOR] R
    [COLOR=navy]Next[/COLOR] Dn
[COLOR=navy]End[/COLOR] [COLOR=navy]Sub[/COLOR]
Regards Mick
 
Upvote 0
Thanks.. this is also working

How about
Code:
Sub FlagCells()
   Dim Rng As Range
   Dim i As Long
   For i = 1 To ActiveSheet.UsedRange.Rows.Count
      For Each Rng In Rows(i).SpecialCells(xlConstants).Areas
         If Rng.Count > 5 Then Rng.Font.Color = vbRed
      Next Rng
   Next i
End Sub
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,065
Messages
6,122,945
Members
449,095
Latest member
nmaske

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