Results 1 to 18 of 18

Draw automatic borders using VBA

Threaded View

  1. #13
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Draw automatic borders using VBA

    OK, try this.

    I fixed some other little problems that were nagging me as well. This will update the boarders as you enter data in the table as you update the week No. and the Quarters Column in the B column. If you want it to update from other columns let me know.

    Private Sub Worksheet_Change(ByVal Target As Range)
        
        Dim start As Range
        Dim finish As Range
            Application.ScreenUpdating = 0
             a = Range("B2").CurrentRegion
            'If Not Intersect(Target, Range("B:M")) Is Nothing Then
             Cells.Borders.LineStyle = 0
               Set start = Range("C2")
               Set finish = Range("C" & Cells(start.Row, 3).End(xlDown).Row)
                 For j = 1 To 1000
                   With Range(Cells(start.Row, 2), Cells(finish.Row - 1, 13))
                     For i = 7 To 11
                      .Borders(i).LineStyle = 1
                     Next i
                   End With
                     Set start = Range("C" & finish.Row)
                     If Cells(start.Row, 3).End(xlDown).Row <= UBound(a) Then
                         Set finish = Range("C" & Cells(start.Row, 3).End(xlDown).Row)
                     ElseIf y = 1 Then
                         GoTo extsub
                     Else
                        Set finish = Range("C" & Cells(Rows.Count, 2).End(xlUp).Row + 1): y = 1
                     End If
                 Next
            ' End If
    extsub:
             Application.ScreenUpdating = 1
    
    End Sub
    Attached Files Attached Files
    Last edited by JapanDave; 06-28-2013 at 05:27 AM.

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.6.0 RC 1