Problems With Range Border Formatting

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,616
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I am using this code to format the borders of a range of cell. I'm notgetting any errors, but I'm not entirely getting the desired results ...

VBA Code:
            Set pda_rng = Worksheets(sht).Range("A12:Q33")
            With pda_rng(xlEdgeLeft).Borders
                .LineStyle = xlContinuous
                .ColorIndex = xlAutomatic
                .Weight = xlThin
            End With
            With pda_rng(xlEdgeTop).Borders
                .LineStyle = xlContinuous
                .ColorIndex = xlAutomatic
                .Weight = xlThin
            End With
            With pda_rng(xlEdgeBottom).Borders
                .LineStyle = xlContinuous
                .ColorIndex = xlAutomatic
                .Weight = xlThin
            End With
            With pda_rng(xlEdgeRight).Borders
                .LineStyle = xlContinuous
                .ColorIndex = xlAutomatic
                .Weight = xlThin
            End With
            With pda_rng(xlInsideVertical).Borders
                .LineStyle = xlContinuous
                .ColorIndex = xlAutomatic
                .Weight = xlThin
            End With
            With pda_rng(xlInsideHorizontal).Borders
                .LineStyle = xlContinuous
                .ColorIndex = xlAutomatic
                .Weight = xlHairline
            End With

This is the result
WS 29-Jun-21.xlsm
ABCDEFGHIJKLMNOPQ
10Record IDDispatchRentalLocationActivityGroomPrepareSignatureLights OnLights Off1234Close
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
CRP


Look specifically at range G12:L12. The top border should be solid xlThin but the top border of L12 is hairline; and the bottom border (of the G12:L12 range), or the interior horizontal borders of pda_range (xlInsideHorizontal) should be xlHairline - but exhibits xlThinG12:K12.

Thoughts?

EDIT: I guess xl2bb doesn't reflect border formats. Here's an image to refer to.
Capture0627a.JPG
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
did you try formating 11throw bottom line only?
not sure why but sometimes the border must be set from both sides 12th row top and11th row bottom.
 
Upvote 0
Hi Radoslaw Poprawski for your help. I reformatted the bottom border of row 11 to xlthin, and that took car of the xlhairline format on the top border of G12. But I still can't resolve the xlThin format of the bottom border of cells G12:K12. I have coded all interior horizontal cells from A12:Q33 to be xlhairline. Why isn't the bottom row of these few cells, also interior horizontal borders of the range, not taking the xlhairline weight?
 
Upvote 0
It should be range.borders(etc) not the otherway round.
 
Upvote 0
Solution
You can also slim that line like
VBA Code:
            Set pda_rng = Worksheets(sht).Range("A12:Q33")
            pda_rng.BorderAround xlContinuous, xlThin, xlColorIndexAutomatic
            With pda_rng.Borders(xlInsideVertical)
                .LineStyle = xlContinuous
                .ColorIndex = xlAutomatic
                .Weight = xlThin
            End With
            With pda_rng.Borders(xlInsideHorizontal)
                .LineStyle = xlContinuous
                .ColorIndex = xlAutomatic
                .Weight = xlHairline
            End With
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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