Consulting

Results 1 to 3 of 3

Thread: Solved: Use of AddShape to add circle

  1. #1
    VBAX Regular
    Joined
    Apr 2009
    Posts
    18
    Location

    Solved: Use of AddShape to add circle

    Hi all, I'm trying to add a circle with the following parameters:

    1. The circle is centred in the middle of the cell
    2. The circle diameter is set by the numerical value entered into the cell

    triggered by Worksheet_Change

    [Ideally there would be an option to set the circle colour and line thickness also]

    Excel 2003, WinXP

    Thanks for your input.
    JohnS

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    Play with the following:[vba]Private Sub Worksheet_Change(ByVal Target As Range)
    With Target
    If IsNumeric(.Value) And .Value > 0 Then
    Set TheCircle = ActiveSheet.Shapes.AddShape(msoShapeOval, .Left + .Width / 2 - .Value / 2, .Top + .Height / 2 - .Value / 2, .Value, .Value)
    ' Optional stuff:
    ' With TheCircle
    ' .LockAspectRatio = msoTrue
    ' With .Line
    ' .Weight = 3.5
    ' .ForeColor.SchemeColor = 10
    ' .BackColor.RGB = RGB(255, 255, 255)
    ' End With
    ' With .Fill
    ' .Solid
    ' .ForeColor.SchemeColor = 43
    ' .Transparency = 0.69
    ' End With
    ' End With
    End If
    End With
    End Sub
    [/vba]
    Last edited by p45cal; 04-29-2010 at 02:07 PM.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    VBAX Regular
    Joined
    Apr 2009
    Posts
    18
    Location

    Smile SOLVED: Use of AddShape to add circle

    p45cal - that is great code. Thanks very much for that.
    Sorry, but I can't see how to set this to SOLVED...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •