Consulting

Results 1 to 3 of 3

Thread: VBA 101

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    VBA 101

    In the following simple macro, what instruction needs to be added so that the rectangle is drawn with its top left corner at the intersect of row 6 and column D (or thereabouts)?


    Sub MakeNewRectangle()
    Dim mySheet As Worksheet
    Dim myShape As Shape
    Dim myCell As Range
    Set mySheet = ActiveSheet
    Set myShape = mySheet.Shapes.AddShape(msoShapeRectangle, 72, 36, 72, 36)
    myShape.Fill.ForeColor.SchemeColor = 10
    End Sub

    I answered my own question :


    Sub MakeNewRectangle()
        Dim mySheet As Worksheet
        Dim myShape As Shape
        Dim myCell As Range
        Set mySheet = ActiveSheet
        Set myShape = mySheet.Shapes.AddShape(msoShapeRectangle, 110, 110, 72, 36)
        myShape.Fill.ForeColor.SchemeColor = 10
    End Sub

  2. #2
    VBAX Tutor
    Joined
    Mar 2005
    Posts
    268
    Location
    But you can do better:

    Sub MakeNewRectangle()
        Dim mySheet As Worksheet
        Dim myShape As Shape
        Dim myCell As Range
        Set mySheet = ActiveSheet
        Set myShape = mySheet.Shapes.AddShape(msoShapeRectangle, _
    mySheet.Columns("D").Left, mySheet.Rows("6").Top, 72, 36)
        myShape.Fill.ForeColor.SchemeColor = 10
    End Sub

  3. #3
    Thanks!!!

Posting Permissions

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