Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Does a shape cover a cell ?

I need a simple boolean function that, give the name of a shape and the
address of a single cell, will return TRUE if the cell is fully or partially
covered by the shape. Otherwise FALSE.

Thanks in advance
--
Gary''s Student - gsnu200764
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Does a shape cover a cell ?


GS,
A Shape has TopLeftCell and BottomRightCell properties.
Those two will give you the range it is over.
Application.Intersect should then answer your question.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)



"Gary''s Student"
wrote in message
I need a simple boolean function that, give the name of a shape and the
address of a single cell, will return TRUE if the cell is fully or partially
covered by the shape. Otherwise FALSE.

Thanks in advance
--
Gary''s Student - gsnu200764
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Does a shape cover a cell ?

Gary's Student,

Function Cover(strShapeName As String, cAdd As String) As Variant
On Error GoTo ErrHandler
With Range(cAdd).Parent.Shapes(strShapeName)
Cover = Not Intersect(Range(cAdd), Range(.TopLeftCell, .BottomRightCell)) Is Nothing
End With
Exit Function
ErrHandler:
Cover = "Bad :-("
End Function


Sub TestTheFunction()
MsgBox Cover("Rectangle 1", "C4")
End Sub



--
HTH,
Bernie
MS Excel MVP


"Gary''s Student" wrote in message
...
I need a simple boolean function that, give the name of a shape and the
address of a single cell, will return TRUE if the cell is fully or partially
covered by the shape. Otherwise FALSE.

Thanks in advance
--
Gary''s Student - gsnu200764



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Does a shape cover a cell ?

I should also have noted that if you want to find out if the shape _Visually_ covers part of a cell,
you are out of luck - the drawing object is rectangular, even if visually it is a line, or curve or
something else.

HTH,
Bernie
MS Excel MVP


"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...
Gary's Student,

Function Cover(strShapeName As String, cAdd As String) As Variant
On Error GoTo ErrHandler
With Range(cAdd).Parent.Shapes(strShapeName)
Cover = Not Intersect(Range(cAdd), Range(.TopLeftCell, .BottomRightCell)) Is Nothing
End With
Exit Function
ErrHandler:
Cover = "Bad :-("
End Function


Sub TestTheFunction()
MsgBox Cover("Rectangle 1", "C4")
End Sub



--
HTH,
Bernie
MS Excel MVP


"Gary''s Student" wrote in message
...
I need a simple boolean function that, give the name of a shape and the
address of a single cell, will return TRUE if the cell is fully or partially
covered by the shape. Otherwise FALSE.

Thanks in advance
--
Gary''s Student - gsnu200764





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Does a shape cover a cell ?

Thanks...this gives me something to work with.
--
Gary''s Student - gsnu200764


"Jim Cone" wrote:


GS,
A Shape has TopLeftCell and BottomRightCell properties.
Those two will give you the range it is over.
Application.Intersect should then answer your question.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)



"Gary''s Student"
wrote in message
I need a simple boolean function that, give the name of a shape and the
address of a single cell, will return TRUE if the cell is fully or partially
covered by the shape. Otherwise FALSE.

Thanks in advance
--
Gary''s Student - gsnu200764



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Does a shape cover a cell ?

Thanks !!
--
Gary''s Student - gsnu200764


"Bernie Deitrick" wrote:

Gary's Student,

Function Cover(strShapeName As String, cAdd As String) As Variant
On Error GoTo ErrHandler
With Range(cAdd).Parent.Shapes(strShapeName)
Cover = Not Intersect(Range(cAdd), Range(.TopLeftCell, .BottomRightCell)) Is Nothing
End With
Exit Function
ErrHandler:
Cover = "Bad :-("
End Function


Sub TestTheFunction()
MsgBox Cover("Rectangle 1", "C4")
End Sub



--
HTH,
Bernie
MS Excel MVP


"Gary''s Student" wrote in message
...
I need a simple boolean function that, give the name of a shape and the
address of a single cell, will return TRUE if the cell is fully or partially
covered by the shape. Otherwise FALSE.

Thanks in advance
--
Gary''s Student - gsnu200764




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Does a shape cover a cell ?

There is no simple way of doing this. You have to get the Top, Left, Width,
and Length of both the cell and shape to determine if there is an overlap

Because the shape and cell are both rectangle you need to test all four
corners of the shape against al four sides of the cell to determine a partial
overlap

for the top left corner of the shape it would be something like this

'four corners of the shape
sxleft = shape.left
sytop = shape.top
sxright = sxleft + shape.width
sxbottom = sytop + shape.height

'four corners of the cell
cxleft = shape.left
cytop = shape.top
cxright = cxleft + shape.width
cxbottom = cytop + shape.height

if (sxleft = cxleft) and sxleft <= cxright) and
(sxtop = cxtop) and sxtop <= cxbottom) then

overlap is true
end if

now repeat for other three conditions of. Instead of sxleft and sxtop use
sxright and sxtop
sxleft and sxbotom
sxright and sxbotom

Only one of the 4 conditions needs to be met to determine overlap.

"Gary''s Student" wrote:

I need a simple boolean function that, give the name of a shape and the
address of a single cell, will return TRUE if the cell is fully or partially
covered by the shape. Otherwise FALSE.

Thanks in advance
--
Gary''s Student - gsnu200764

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Does a shape cover a cell ?

Function bCovers(obj As Object, rng As Range) As Boolean
With obj
If .Left <= rng.Left Then
If .Top <= rng.Top Then
If .Left + .Width = rng.Left + rng.Width Then
bCovers = .Top + .Height = rng.Top + rng.Height
End If
End If
End If
End With
End Function

obj as Object to cater for any drawingobject type, eg simply Selection, or
if a Shape, but change to As Shape if you prefer.

Regards,
Peter T


"Gary''s Student" wrote in message
...
I need a simple boolean function that, give the name of a shape and the
address of a single cell, will return TRUE if the cell is fully or

partially
covered by the shape. Otherwise FALSE.

Thanks in advance
--
Gary''s Student - gsnu200764



  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Does a shape cover a cell ?

I read "fully covered" but misread "or partially".
The function I posted returns true for "fully covers" only, but I see others
have posted enough for you.

Regards,
Peter T

"Peter T" <peter_t@discussions wrote in message
...
Function bCovers(obj As Object, rng As Range) As Boolean
With obj
If .Left <= rng.Left Then
If .Top <= rng.Top Then
If .Left + .Width = rng.Left + rng.Width Then
bCovers = .Top + .Height = rng.Top + rng.Height
End If
End If
End If
End With
End Function

obj as Object to cater for any drawingobject type, eg simply Selection, or
if a Shape, but change to As Shape if you prefer.

Regards,
Peter T


"Gary''s Student" wrote in

message
...
I need a simple boolean function that, give the name of a shape and the
address of a single cell, will return TRUE if the cell is fully or

partially
covered by the shape. Otherwise FALSE.

Thanks in advance
--
Gary''s Student - gsnu200764





  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Does a shape cover a cell ?

Thanks !
--
Gary''s Student - gsnu200764


"Joel" wrote:

There is no simple way of doing this. You have to get the Top, Left, Width,
and Length of both the cell and shape to determine if there is an overlap

Because the shape and cell are both rectangle you need to test all four
corners of the shape against al four sides of the cell to determine a partial
overlap

for the top left corner of the shape it would be something like this

'four corners of the shape
sxleft = shape.left
sytop = shape.top
sxright = sxleft + shape.width
sxbottom = sytop + shape.height

'four corners of the cell
cxleft = shape.left
cytop = shape.top
cxright = cxleft + shape.width
cxbottom = cytop + shape.height

if (sxleft = cxleft) and sxleft <= cxright) and
(sxtop = cxtop) and sxtop <= cxbottom) then

overlap is true
end if

now repeat for other three conditions of. Instead of sxleft and sxtop use
sxright and sxtop
sxleft and sxbotom
sxright and sxbotom

Only one of the 4 conditions needs to be met to determine overlap.

"Gary''s Student" wrote:

I need a simple boolean function that, give the name of a shape and the
address of a single cell, will return TRUE if the cell is fully or partially
covered by the shape. Otherwise FALSE.

Thanks in advance
--
Gary''s Student - gsnu200764



  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Does a shape cover a cell ?

Thank you. Your response and the others have given me enough insight to get
where I needed to go:

If graphics obscure important cells, move the graphics to the right.


--
Gary''s Student - gsnu200764


"Peter T" wrote:

I read "fully covered" but misread "or partially".
The function I posted returns true for "fully covers" only, but I see others
have posted enough for you.

Regards,
Peter T

"Peter T" <peter_t@discussions wrote in message
...
Function bCovers(obj As Object, rng As Range) As Boolean
With obj
If .Left <= rng.Left Then
If .Top <= rng.Top Then
If .Left + .Width = rng.Left + rng.Width Then
bCovers = .Top + .Height = rng.Top + rng.Height
End If
End If
End If
End With
End Function

obj as Object to cater for any drawingobject type, eg simply Selection, or
if a Shape, but change to As Shape if you prefer.

Regards,
Peter T


"Gary''s Student" wrote in

message
...
I need a simple boolean function that, give the name of a shape and the
address of a single cell, will return TRUE if the cell is fully or

partially
covered by the shape. Otherwise FALSE.

Thanks in advance
--
Gary''s Student - gsnu200764






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
my curser changed from arrow shape to a cross shape???? bj New Users to Excel 1 February 5th 07 02:47 PM
cell background cover [email protected] Excel Worksheet Functions 2 July 29th 06 02:45 PM
HELP! Single cell formula to calculate weeks cover of stock on forward sales. [email protected] Excel Worksheet Functions 2 January 13th 06 10:24 AM
Deleting a shape and the cell contents the shape is in. Dave Peterson[_3_] Excel Programming 1 October 9th 03 03:36 PM
Deleting a shape and the cell contents the shape is in. Tom Ogilvy Excel Programming 0 October 9th 03 03:43 AM


All times are GMT +1. The time now is 01:56 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"