How to ignore Overlapping shapes with VBA code

gsrahn91

New Member
Joined
May 9, 2019
Messages
4
The code as is works in most situations however sometimes when a bar slightly over laps it will count in the range and sometimes I can't get it out of the range. This code is going into a document that I don't use it's used by other people who produce a schedule and for whatever reason they have used shapes as their people to overlay on a time sheet. Thank you to everyone who looks at this and give feedback or input. I'm trying to come up with solutions that don't require new training. I think the solution is out there, but I get hung up on the syntax of VBA coding.


Regards
G


Code below


Code:
Function CountShapes(rngSearch As Range) As Long
   Dim sh As Shape
   
'will count +1 each shape that isn't blue in the current range (I.E. =CountShapes(A1:10)
   For Each sh In rngSearch.Parent.Shapes
      If Not Intersect(rngSearch, Range(sh.TopLeftCell, sh.BottomRightCell)) Is Nothing Then
      If Not sh.Fill.ForeColor.RGB = RGB(91,155,213) Then CountShapes = CountShapes + 1
      End If
   Next sh


'will count -1 each shape that is blue in the current range to minus out the bar under the blue one (I.E. =CountShapes(A1:10)
   For Each sh In rngSearch.Parent.Shapes
      If Not Intersect(rngSearch, Range(sh.TopLeftCell, sh.BottomRightCell)) Is Nothing Then
      If sh.Fill.ForeColor.RGB = RGB(91,155,213) Then CountShapes = CountShapes - 1
      End If
   Next sh


'will count -1 each shape that is a blue line in the current range (I.E. =CountShapes(A1:10)
   For Each sh In rngSearch.Parent.Shapes
      If Not Intersect(rngSearch, Range(sh.TopLeftCell, sh.BottomRightCell)) Is Nothing Then
      If sh.Line.ForeColor.RGB = RGB(0,0,255) Then CountShapes = CountShapes - 1
      End If
   Next sh


'this part of the code doesn't work, I can't figure it out. But in theory it should try to look at the width of the shape in the range and subtract one from it. 
   For Each sh In rngSearch.Parent.Shapes
      If Not Intersect(rngSearch, Range(sh.TopLeftCell, sh.BottomRightCell)) Is Nothing Then
      If sh.ShapeRange.ScaleWidth < 0.9743589494 Then CountShapes = CountShapes - 1
      End If
   Next sh


End Function
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Cross posted https://www.excelforum.com/excel-pr...nting-shapes-not-by-topleftcell-property.html

While we do not prohibit Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules).
This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.
 
Upvote 0
Hey Fluff, I can't post a saying it's a cross post on my original post back on the other forum. It says i'm not allowed to post links.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,171
Members
453,021
Latest member
Justyna P

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