+ Reply to Thread
Results 1 to 3 of 3

Thread: Can you draw lines through the center of cells, using cell numbers as references?

  1. #1
    Registered User
    Join Date
    12-07-2006
    Posts
    36

    Question Can you draw lines through the center of cells, using cell numbers as references?

    I know you can draw lines on a worksheet (via the drawing tools), using macros like this:

    Private Sub CommandButton1_Click()
    ActiveSheet.Shapes.AddLine(168#, 12.75, 168#, 102#).Select
    End Sub

    But the position references for the AddLine method are point coordinates.
    Is it possible to draw continous,vertical lines down through the center of cells on a worksheet using the cell numbers as references?

    (I have tried using the Border methods, but these only allow you to draw lines on the edge of cells.)

  2. #2
    Forum Guru mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2007/2010
    Posts
    3,004
    Try

    Sub Test()
    Call DrawLine("B1", "B10")
    End Sub
    
    Sub DrawLine(Cell1, Cell2)
    ActiveSheet.Shapes.AddLine(Range(Cell1).Left + (Range(Cell1).Width / 2), Range(Cell1).Top, Range(Cell2).Left + (Range(Cell2).Width / 2), Range(Cell2).Top + Range(Cell2).Height).Select
    End Sub
    Martin

    Eighty Twenty Spreadsheet Automation http://homepage.ntlworld.com/martin.rice1/ for all your Excel customisation and consulting needs.

    If my solution has saved you time and/or money, please consider donating to Cancer Research UK.

  3. #3
    Registered User
    Join Date
    12-07-2006
    Posts
    36
    Many thanks, Martin.
    That's excellent!


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.2.0