Add bottom border to a row for each sheet meeting a certain criteria

Camille22

New Member
Joined
Apr 14, 2016
Messages
12
Hi There,

I am new to this site and wanted to see if someone could please help.

I have already some code , it is just not looping to the next worksheet.

What I am trying to do is add a bottom border to a row (until last used cell) if the value in column A = "Starting Point"

Code:
[COLOR=blue]Sub[/COLOR] Border() 
     
    [COLOR=blue]Dim[/COLOR] r [COLOR=blue]As[/COLOR] Range, r2 [COLOR=blue]As[/COLOR] Range 
    [COLOR=blue]Dim[/COLOR] ws [COLOR=blue]As[/COLOR] Worksheet 
     
     
    [COLOR=blue]For Each[/COLOR] ws [COLOR=blue]In[/COLOR] ThisWorkbook.Worksheets 
        [COLOR=blue]With[/COLOR] ws 
            [COLOR=blue]Set[/COLOR] r = .Range("A1:A" & .Range("A" & Rows.Count).End(xlUp).Row) 
            [COLOR=blue]For Each[/COLOR] r2 [COLOR=blue]In[/COLOR] r 
                [COLOR=blue]If[/COLOR] r2.Value = "Starting Point" [COLOR=blue]Then[/COLOR] 
                    r2.Select 
                     
                    [COLOR=blue]With[/COLOR] r2 
                         
                        lr = ActiveCell.Row 
                        lc = ActiveCell.End(xlToRight).Column 
                        Range(ActiveCell, Cells(lr, lc)).Select 
                         
                         
                        Selection.borders(xlEdgeBottom).Weight = xlThin 
                         
                         
                         [COLOR=darkgreen]'r = r2 + 1[/COLOR]
                    [COLOR=blue]End With[/COLOR] 
                     
                [COLOR=blue]End[/COLOR] [COLOR=blue]If[/COLOR] 
                 [COLOR=darkgreen]' Worksheets(ActiveSheet.Index + 1).Select[/COLOR]
            [COLOR=blue]Next[/COLOR] r2 
             [COLOR=darkgreen]' Next[/COLOR]
        [COLOR=blue]End With[/COLOR] 
    [COLOR=blue]Next[/COLOR] 
[COLOR=blue]End Sub[/COLOR]
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Maybe this
Code:
Sub Border()
    Dim r As Range, r2 As Range
    Dim ws As Worksheet
    For Each ws In Worksheets
        ws.Activate
            Set r = Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row)
            For Each r2 In r
                If r2.Value = "Starting Point" Then
                    With r2
                        lr = r2.Row
                        lc = r2.End(xlToRight).Column
                        Range(r2, Cells(lr, lc)).Borders(xlEdgeBottom).Weight = xlThin
                         'r = r2 + 1
                    End With
                End If
            Next r2
    Next ws
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,599
Messages
6,120,453
Members
448,967
Latest member
grijken

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top