Border in diffrent rows

hendrikbez

Board Regular
Joined
Dec 13, 2013
Messages
95
Office Version
  1. 2021
Platform
  1. Windows
I have this code, but it does not doing what I need. did search with Google, but cannot find any info
is the following possible, if so how.

I want to highlight say 2 rows, then it must place a border on top and bottom of the rows.
The nesx one can be 4 rows and so on.
the rows will always be different sizes.
Code:
<code>Sub RedOutlineCells()
    Dim rng As Range

    Set rng = Range("A1:k4")

    With rng.Borders
        .LineStyle = xlContinuous
        .Color = vbRed
        .Weight = xlThin
    End With
End Sub</code>
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
the'Borders' part needs an argument to tell it which border. If you type an open bracket you will see a list of all possibilities so for the top border it would be:

Code:
 With rng.Borders(xlEdgeTop)
 
Upvote 0
Did change the line, it changes the top of row 4, but how can I do this if I higlit about 4 rows anywhere on the sheet and when run code it will put a line on top of the first row and a line on the last row bottom
 
Upvote 0
Code:
Sub RedOutlineCells()
    Dim rng As Range


    Set rng = Selection


    'Top
    With rng.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .Color = vbRed
        .Weight = xlThin
    End With
    'Bottom
    With rng.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .Color = vbRed
        .Weight = xlThin
    End With
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,209
Members
453,022
Latest member
RobertV1609

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