View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.misc
Gord Dibben Gord Dibben is offline
external usenet poster
 
Posts: 22,906
Default Macro to Fit AutoShape over Range?

You want a filled rectangle?

Sub Yellow_Rectangle()
Dim X, y As Single, area As Range
For Each area In Selection.Areas
With area
X = .Height * 0#
y = .Width * 0#
ActiveSheet.Rectangles.Add Top:=.Top - X, Left:=.Left - y, _
Height:=.Height + 1 * X, Width:=.Width + 1 * y
End With
With ActiveSheet.Rectangles(ActiveSheet.Rectangles.Coun t)
.Interior.ColorIndex = 2
.ShapeRange.AutoShapeType = msoShapeRectangle
End With
Next area
End Sub

Note: will work on multiple select ranges


Gord Dibben MS Excel MVP



On Tue, 22 Jul 2008 10:12:04 -0700, Wart
wrote:

It seems to me that inserting and manipulating AutoShapes is incredibly
straightforward in Excel, but users of a form in our office have asked if
there's a way to more quickly make rectangles that would EXACTLY cover
whatever range of cells they have selected. (This is all the more annoying of
a request, because most of the users are on Excel for Mac, whose Formatting
Palette makes this sort of thing even easier.)

Anyway: can a macro be written that will do this? I'm imagining that, after
a user left-clicks and drags through any area, that they'll right-click,
select the macro from the shortcut menu, and the code will plop a rectangle
over the area. (I already have a number of custom options on the shortcut
menu, so that I can do that part myself.)

I know this is all absurd, but any help anyone can offer would be much
appreciated!