Results 1 to 18 of 18

Draw automatic borders using VBA

Threaded View

  1. #15
    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

    Repace the code with this,

    You really should have posted an exact copy of the workbook in the first place. I am on my 8th beer right now and it is getting hard to think straight! LOL

    Private Sub Worksheet_Change(ByVal Target As Range)
        
        Dim start As Range
        Dim finish As Range
        Dim a As Long, i As Long, j As Long
            Application.ScreenUpdating = 0
              For i = 2 To 5
                If a < Cells(Rows.Count, i).End(xlUp).Row Then
                  a = Cells(Rows.Count, i).End(xlUp).Row
                End If
              Next i
            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 <= a Then
                         Set finish = Range("C" & Cells(start.Row, 3).End(xlDown).Row)
                     ElseIf y = 1 Then
                         GoTo extsub
                     Else
                        Set finish = Range("C" & a + 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 06:46 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