vba add shape on click

hwkeyser

Board Regular
Joined
Jun 7, 2011
Messages
116
Hello all,

I have an excel sheet which requires donuts being drawn all over it on a regular basis.

I'm hoping to write a macro that for a certain range on a spreadsheet, for arguments sake lets call it A1: I10, upon clicking or double-clicking within the cells, vba adds a donut originating at the middle of that cell.

I can imagine it uses the addShape command-- beyond that I don't have a clue where to get started, but if someone can get the shape(s) to appear, i can easily modify it to my needs from there.

so, in short-

  • Click a cell within the range A1:I10
  • addShape msoShapeDonut (originating aligned to the center of the cell)
  • (optional) Will not circle blank cells

any help would be appreciated,

Henry
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Add this this to the sheet in question's code module:
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Set xxx = Intersect(Range("A1:I10"), Target)
If Not xxx Is Nothing Then
    If Not IsEmpty(Target) Then
        Cancel = True
        mySize = 10
        Set myShape = Me.Shapes.AddShape(msoShapeDonut, Target.Left + Target.Width / 2 - mySize / 2, Target.Top + Target.Height / 2 - mySize / 2, mySize, mySize)
        myShape.LockAspectRatio = msoTrue
        myShape.ScaleWidth 2, msoFalse, msoScaleFromMiddle
    End If
End If
End Sub
It works on a double-click, not a single click - sorry.
(Excel 2010)
 
Last edited:
Upvote 0
This is pretty close to what i need- i just cant seem to find the attribute to lessen the gauge of the donut-- i'm looking for a nearly hollow circle.

Can you help with that too?
 
Upvote 0
add
myShape.Adjustments.Item(1) = 0.02
or use an oval instead of a donut with the fill invisible. Then change the line thickness.
 
Upvote 0

Forum statistics

Threads
1,224,583
Messages
6,179,678
Members
452,937
Latest member
Bhg1984

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