View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
[email protected] sbwhitney@utah.gov is offline
external usenet poster
 
Posts: 1
Default Counting Bordered Cells

On Sunday, May 25, 2014 10:06:37 PM UTC-6, wrote:
Complete VBA noob.



I have created a module in VBA and have tried the following to count cells in a range on one sheet that have four sides bordered and have the count results in a cell on another sheet.

Line style and color do not matter.



Function CountBrd(rng As Range)



Dim i As Integer

Dim cell As Range

i = 0

For Each cell In rng



If cell.Borders(xlEdgeLeft).LineStyle < xlLineStyleNone

AndIf cell.Borders(xlEdgeRight).LineStyle < xlLineStyleNone

AndIf cell.Borders(xlEdgeBottom).LineStyle < xlLineStyleNone

AndIf cell.Borders(xlEdgeTop).LineStyle < xlLineStyleNone



Then

i = i + 1

End If

Next



CountBrd = i



End Function



On another sheet in a cell I have =CountBrd("Sheetname""Range")



I get a couple of syntax errors and since I know zero about this I come to you for help.


Thanks Claus,

When I run the function I do receive a result, but it is not accurate. IT may be counting the cells that have a left border by default.
This may be helpful, by default the range will have the top and left cell already with a border. I need to count the cells in the range when they have all four sides bordered.

I see this line " If rngC.Borders(xlEdgeLeft).LineStyle _" is that looking at only cells with a left border?