+ Reply to Thread
Results 1 to 6 of 6

AutoFill border

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    11-20-2005
    Posts
    256

    AutoFill border

    Hi all,

    Goal: if a value is in Column B, have the inside border auto fill down, in Columns D through BE.
    From Row 5 down to that row.

    This works for the row where i put the value in Column B but if i clear out some of the bottom rows
    in Column B the Format stays.

    I guess what i am trying to do is clear the format on that row if the value
    in Column B is tken out. Been trying some IF / ELSE stuff but to no avail.

    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim LRow As Long
        
        If Target.Column = 2 Then
            LRow = Cells(Rows.Count, 5).End(xlUp).Row
            With Range("D" & Target.Row, "BE" & Target.Row)
                
                With .Borders(xlInsideVertical)
                    .LineStyle = xlDash
                    .Weight = xlThin
                    .ColorIndex = xlAutomatic
                End With
                
            End With
        End If
    End Sub
    Thx
    Dave
    "The game is afoot Watson"

  2. #2
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    Try clearing the borders for columns D to BE - all rows then have your macro apply border formating

    
    Private Sub Worksheet_Change(ByVal Target As Range)
       Dim LRow As Long
       
       If Target.Column = 2 Then
          With Columns("d:be")
             .Borders(xlDiagonalDown).LineStyle = xlNone
             .Borders(xlDiagonalUp).LineStyle = xlNone
             .Borders(xlEdgeLeft).LineStyle = xlNone
             .Borders(xlEdgeTop).LineStyle = xlNone
             .Borders(xlEdgeBottom).LineStyle = xlNone
             .Borders(xlEdgeRight).LineStyle = xlNone
             .Borders(xlInsideVertical).LineStyle = xlNone
             .Borders(xlInsideHorizontal).LineStyle = xlNone
          End With
          LRow = Cells(Rows.Count, 5).End(xlUp).Row
          With Range("D" & Target.Row, "BE" & Target.Row)
          
             With .Borders(xlInsideVertical)
                .LineStyle = xlDash
                .Weight = xlThin
                .ColorIndex = xlAutomatic
             End With
          
          End With
       End If
    End Sub

  3. #3
    Forum Contributor
    Join Date
    11-20-2005
    Posts
    256
    Hi mudraker,

    Thanks for your reply. As written your code clears all the Borders in Columns
    D:BE as i asked, but my code dosen't fill them back in, down to the last cell in Column B.

    So i will go back to the drawing board.

    Seems this line isn't doing anything.
    LRow = Cells(Rows.Count, 5).End(xlUp).Row
    I am trying to make it start on line 5, going down.
    Quote Originally Posted by mudraker
    Try clearing the borders for columns D to BE - all rows then have your macro apply border formating

    
    Private Sub Worksheet_Change(ByVal Target As Range)
       Dim LRow As Long
       
       If Target.Column = 2 Then
          With Columns("d:be")
             .Borders(xlDiagonalDown).LineStyle = xlNone
             .Borders(xlDiagonalUp).LineStyle = xlNone
             .Borders(xlEdgeLeft).LineStyle = xlNone
             .Borders(xlEdgeTop).LineStyle = xlNone
             .Borders(xlEdgeBottom).LineStyle = xlNone
             .Borders(xlEdgeRight).LineStyle = xlNone
             .Borders(xlInsideVertical).LineStyle = xlNone
             .Borders(xlInsideHorizontal).LineStyle = xlNone
          End With
          LRow = Cells(Rows.Count, 5).End(xlUp).Row
          With Range("D" & Target.Row, "BE" & Target.Row)
          
             With .Borders(xlInsideVertical)
                .LineStyle = xlDash
                .Weight = xlThin
                .ColorIndex = xlAutomatic
             End With
          
          End With
       End If
    End Sub

  4. #4
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    Your code starts at the bottom row in column 5 (E) and goes up. But you do not use the variable result within your code.



    Try changing your code the following 2 commands

    LRow = Cells(Rows.Count, "b").End(xlUp).Row
    or
    LRow = Cells(5, "b").End(xlDown).Row
    
    And
    
    With Range("D" & LRow, "BE" & Lrow)
    Last edited by mudraker; 01-16-2007 at 04:23 PM.

  5. #5
    Forum Contributor
    Join Date
    11-20-2005
    Posts
    256
    Ok here is where i am at:

    It seems that it does everything i need except when i put a value
    in Column B, the formating occurs only on that row and not from
    row 5 down to that line. So all the rows in between are 'no borders'

    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim LRow As Long
        
        If Target.Column = 2 Then
            With Columns("D:BE")
                .Borders(xlInsideVertical).LineStyle = xlNone
            End With
            'old
            '        LRow = Cells(Rows.Count, 5).End(xlUp).Row
            'new
            '        LRow = Cells(Rows.Count, "B").End(xlUp).Row
            'new
            LRow = Cells(5, "B").End(xlDown).Row
            
            With Range("D" & LRow, "BE" & LRow)
                
                With .Borders(xlInsideVertical)
                    .LineStyle = xlDash
                    .Weight = xlThin
                    .ColorIndex = xlAutomatic
                End With
                
            End With
        End If
    End Sub


    Quote Originally Posted by mudraker
    Your code starts at the bottom row in column 5 (E) and goes up. But you do not use the variable result within your code.



    Try changing your code the following 2 commands

    LRow = Cells(Rows.Count, "b").End(xlUp).Row
    or
    LRow = Cells(5, "b").End(xlDown).Row
    
    And
    
    With Range("D" & LRow, "BE" & Lrow)

  6. #6
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    If you want to format from row 5 down to the row that was changed then you do not need to use
    LRow = Cells(5, "B").End(xlDown).Row
    Which will give you down to the last used row in Column B.

    And yes I made an error in the code I previously posted
    With Range("D" & LRow, "BE" & Lrow)
    should have been
    With Range("D5", "BE" & Lrow)


    This code will format from row 5 to target.row

    Private Sub Worksheet_Change(ByVal Target As Range)
        If Target.Column = 2 Then
            With Columns("D:BE")
                .Borders(xlInsideVertical).LineStyle = xlNone
            End With
    
            With Range("D5:BE" & Target.Row)
                With .Borders(xlInsideVertical)
                    .LineStyle = xlDash
                    .Weight = xlThin
                    .ColorIndex = xlAutomatic
                End With
                
            End With
        End If
    End Sub

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