Number of rows between a certain condition in vba

mrmalum

New Member
Joined
Jul 28, 2011
Messages
1
Hi.
Right now I have a sheet that is sectioned. Each section going down the sheet has a title that is a different size and color font than the rest of the data. Each section is also a different size. What I need is some code that will determine how many rows there are between each title so I can then use that to scan each section individually to find the number of cells with a certain color.

I guess what I'm asking is if there is a way to determine how many rows are between rows with a certain font size or color?
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
One of the quickest ways would probably be to use "SpecialCells". Unfortunately, cell font or color are not one of the types you can search for. You could possibly include a comment or empty cell on each row of your section titles and use it that way. Otherwise, I believe you will have to read down an entire column and check the font and/or color one cell at a time and record the addresses of the hits.

Here's a sample that assumes you have placed a comment somewhere on each row that is considered a "Section Title".

Hope it helps.

Gary

Code:
Public Sub Test()

Dim oRange As Range

Set oRange = ActiveSheet.UsedRange.SpecialCells(xlCellTypeComments)

'xlCellTypeAllFormatConditions
'xlCellTypeAllValidation
'xlCellTypeBlanks
'xlCellTypeComments
'xlCellTypeConstants
'xlCellTypeFormulas
'xlCellTypeLastCell
'xlCellTypeSameFormatConditions
'xlCellTypeSameValidation
'xlCellTypeVisible

MsgBox oRange.Address

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,583
Messages
6,179,682
Members
452,937
Latest member
Bhg1984

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