Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 19
Default Macro to Fit AutoShape over Range?

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!


  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 320
Default Macro to Fit AutoShape over Range?

This macro creates an exact ractangle and if you click it, it goes away.
Sub rect()
On Error Resume Next
Set Startingcell = Application.InputBox("Enter address of starting cell
for the rectangle", _
default:=ActiveCell.Address, Type:=8)

If Startingcell.Address = "" Then Exit Sub
Set Endingcell = Application.InputBox("Enter address of ending cell for
the rectangle", Type:=8)
If Endingcell.Address = "" Then Exit Sub
'format is left, top, width, height
If Startingcell.Column 1 Then
leftamt = Range("a1", Startingcell.Offset(, -1)).Width
Else: leftamt = 0
End If
If Startingcell.Row 1 Then
topamt = Range("a1", Startingcell.Offset(-1)).Height
Else: topamt = 0
End If
Widthamt = Range(Startingcell.Address, Endingcell.Address).Width
Heightamt = Range(Startingcell.Address, Endingcell.Address).Height
ActiveSheet.Rectangles.Add leftamt, topamt, Widthamt, Heightamt
ActiveSheet.Rectangles(ActiveSheet.Rectangles.Coun t).OnAction = "Deleteme"
End Sub
Sub Deleteme()
ActiveSheet.Rectangles(Application.Caller).Delete
End Sub

"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!


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10,593
Default Macro to Fit AutoShape over Range?

Sub CreateAutoShape()

With ActiveSheet.Shapes

.AddShape(msoShapeRectangle, _
Selection.Left, Selection.Top, Selection.Width,
Selection.Height).Select
End With

With Selection.ShapeRange
.Fill.Visible = msoTrue
.Fill.Solid
.Fill.ForeColor.SchemeColor = 65
.Fill.Transparency = 0.67
.Line.Weight = 0.75
.Line.DashStyle = msoLineSquareDot
.Line.ForeColor.SchemeColor = 51
.Line.BackColor.RGB = RGB(255, 255, 255)
.Fill.Visible = msoTrue
.Fill.Solid
.Fill.ForeColor.SchemeColor = 47
.Fill.Transparency = 0.74
End With
End Sub


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Wart" wrote in message
...
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!




  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default Macro to Fit AutoShape over Range?

Select a block of cells and run:

Sub Macro1()
Set r = Selection
ActiveSheet.Shapes.AddShape(msoShapeRectangle, 46.5, 12#, 193.5, 53.25).Select

Selection.Top = r.Top
Selection.Left = r.Left
Selection.Height = r.Height
Selection.Width = r.Width
End Sub

--
Gary''s Student - gsnu200795


"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!


  #5   Report Post  
Posted to microsoft.public.excel.misc
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!





  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 19
Default Macro to Fit AutoShape over Range?

Thanks, Bob, for the fast and helpful response! Both yours and Gary"s
Student's response, below, work great! EXCELLENT!

"Bob Umlas, Excel MVP" wrote:

This macro creates an exact ractangle and if you click it, it goes away.
Sub rect()
On Error Resume Next
Set Startingcell = Application.InputBox("Enter address of starting cell
for the rectangle", _
default:=ActiveCell.Address, Type:=8)

If Startingcell.Address = "" Then Exit Sub
Set Endingcell = Application.InputBox("Enter address of ending cell for
the rectangle", Type:=8)
If Endingcell.Address = "" Then Exit Sub
'format is left, top, width, height
If Startingcell.Column 1 Then
leftamt = Range("a1", Startingcell.Offset(, -1)).Width
Else: leftamt = 0
End If
If Startingcell.Row 1 Then
topamt = Range("a1", Startingcell.Offset(-1)).Height
Else: topamt = 0
End If
Widthamt = Range(Startingcell.Address, Endingcell.Address).Width
Heightamt = Range(Startingcell.Address, Endingcell.Address).Height
ActiveSheet.Rectangles.Add leftamt, topamt, Widthamt, Heightamt
ActiveSheet.Rectangles(ActiveSheet.Rectangles.Coun t).OnAction = "Deleteme"
End Sub
Sub Deleteme()
ActiveSheet.Rectangles(Application.Caller).Delete
End Sub

"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!


  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 19
Default Macro to Fit AutoShape over Range?

Hey, there--
See my reply to Bob, above--Both this and the other macros (I see Bob pilips
just replied, too!) are great! Probably my coworkers will just spend the rest
of the day making rectangles, now.

Thank you all so much!

"Gary''s Student" wrote:

Select a block of cells and run:

Sub Macro1()
Set r = Selection
ActiveSheet.Shapes.AddShape(msoShapeRectangle, 46.5, 12#, 193.5, 53.25).Select

Selection.Top = r.Top
Selection.Left = r.Left
Selection.Height = r.Height
Selection.Width = r.Width
End Sub

--
Gary''s Student - gsnu200795


"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!


  #8   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 19
Default Macro to Fit AutoShape over Range?

See my messages to the others, above. Now I have THREE different macros to
play with--perhaps I'll ask my coworkers to vote. :-) Truly, all of you have
made this day better than it was--thanks!

"Bob Phillips" wrote:

Sub CreateAutoShape()

With ActiveSheet.Shapes

.AddShape(msoShapeRectangle, _
Selection.Left, Selection.Top, Selection.Width,
Selection.Height).Select
End With

With Selection.ShapeRange
.Fill.Visible = msoTrue
.Fill.Solid
.Fill.ForeColor.SchemeColor = 65
.Fill.Transparency = 0.67
.Line.Weight = 0.75
.Line.DashStyle = msoLineSquareDot
.Line.ForeColor.SchemeColor = 51
.Line.BackColor.RGB = RGB(255, 255, 255)
.Fill.Visible = msoTrue
.Fill.Solid
.Fill.ForeColor.SchemeColor = 47
.Fill.Transparency = 0.74
End With
End Sub


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Wart" wrote in message
...
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!





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
AutoShape skid812pb Excel Discussion (Misc queries) 6 June 3rd 09 12:44 PM
Macro deletes row in range, macro then skips the row moved up steven.holloway Excel Discussion (Misc queries) 8 June 11th 08 11:40 AM
autoshape macro jackrobyn1 Excel Discussion (Misc queries) 1 October 13th 07 11:33 PM
autoshape tony Excel Discussion (Misc queries) 1 February 24th 07 09:35 PM
NAME OF AUTOSHAPE Ronbo Excel Discussion (Misc queries) 3 August 18th 05 10:09 PM


All times are GMT +1. The time now is 06:55 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"