Consulting

Results 1 to 4 of 4

Thread: Creating shapes and position them

  1. #1

    Creating shapes and position them

    Hey everybody,

    Iam just starting to learn VBA programming in Excel.

    All I want is to create a big circle and some small circles in excel. The big circle has to be in a certain position.

    My excel sheet looks like this:

    Capture.JPG
    My code looks like this:

    Private Sub CommandButton1_Click()

    Dim diam
    diam = Range("K8").Value * 10

    ActiveSheet.Shapes.AddShape msoShapeOval, 50, 50, diam, diam

    End Sub


    The code creates the big circle but it is in the wrong position as you can see in the picture. I would like to have it somewhere close to I25. Then by clicking on the command button I also want to create 7 more small circles with a diameter of 5.922. (please see also the picture cell K17 and K25). The position of the small circles is not important.

    Thank you guys so much

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Try this

    Dim nTop As Double
    Dim nLeft As Double
    Dim diam
     
        diam = Range("K8").Value * 10
        
        With Range("I25")
        
            nTop = .Top
            nLeft = .Left
        End With
        
        ActiveSheet.Shapes.AddShape msoShapeOval, nLeft, nTop, diam, diam
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,875
    …with a bit added for the smaller circles:
    Dim nTop As Double
    Dim nLeft As Double
    Dim diam, i As Long
     
    diam = Range("K8").Value * 10
    With Range("I25")
      nTop = .Top
      nLeft = .Left
    End With
    ActiveSheet.Shapes.AddShape msoShapeOval, nLeft, nTop, diam, diam
    diam = Range("K25").Value * 10
    For i = 1 To Range("K17").Value
      ActiveSheet.Shapes.AddShape msoShapeOval, nLeft + i * 3, nTop + i * 3, diam, diam
    Next i
    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.

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location

    Wink …with a bit added for the smaller circles:

    Quote Originally Posted by p45cal View Post
    …with a bit added for the smaller circles
    I noticed I missed that bit afterwards so corrected the code, I guessed where the OP wanted them as you did but I used a multiplier of 10 not 3, but was holding it in reserve for when the OP pointed out my omission ... and I could say 'here is one I prepared earlier'
    Last edited by Bob Phillips; 04-02-2018 at 09:55 AM.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Tags for this Thread

Posting Permissions

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