Consulting

Results 1 to 4 of 4

Thread: Plotting an arrow in excel using VBA

  1. #1

    Plotting an arrow in excel using VBA

    Hi Guys!

    I am a little stuck in my macro build. I don't know what I'm trying to do is achievable. I need a macro that looks into a cell (e.g A2 and G2). These cells have start and end dates. These dates are then compared to merged cells starting column MN row 6 all the way into calendar which is plotted horizontally. Therefore when start date is matched we plot a line all the way to end date, preferribly double arrow. <-------------------->

    Any ideas?

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    This should get you started

    [VBA]Dim arrow As Shape
    Dim startCell As Range
    Dim endCell As Range

    With ActiveSheet

    On Error Resume Next
    .Shapes("dateline").Delete
    On Error GoTo 0

    Set startCell = .Rows(6).Find(.Range("A2").Value)
    Set endCell = .Rows(6).Find(.Range("G2").Value)
    Set arrow = .Shapes.AddConnector(msoConnectorStraight, startCell.Left, startCell.Top - 10, endCell.Left + endCell.Width, startCell.Top - 10)
    arrow.Line.BeginArrowheadStyle = msoArrowheadOpen
    arrow.Line.EndArrowheadStyle = msoArrowheadOpen
    arrow.Name = "dateline"
    End With[/VBA]
    ____________________________________________
    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
    Thanks xld. That will indeed get me started! Will let you know on progress.

    Many thanks!
    Last edited by Ray.Mason; 05-30-2012 at 05:02 AM.

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    One small change to span the end of the final merged cell

    [VBA]Dim arrow As Shape
    Dim startCell As Range
    Dim endCell As Range

    With ActiveSheet

    On Error Resume Next
    .Shapes("dateline").Delete
    On Error GoTo 0

    Set startCell = .Rows(6).Find(.Range("A2").Value)
    Set endCell = .Rows(6).Find(.Range("G2").Value)
    Set arrow = .Shapes.AddConnector(msoConnectorStraight, _
    startCell.Left, _
    startCell.Top - 10, _
    endCell.Left + endCell.MergeArea.Width, _
    startCell.Top - 10)
    arrow.Line.BeginArrowheadStyle = msoArrowheadOpen
    arrow.Line.EndArrowheadStyle = msoArrowheadOpen
    arrow.Name = "dateline"
    End With[/VBA]
    ____________________________________________
    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

Posting Permissions

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