Border problem

xsmurf

Board Regular
Joined
Feb 24, 2007
Messages
55
Office Version
  1. 365
Platform
  1. Windows
Hello,

In my worksheet i have a range of data form column B to AG.
Within these columns i hide the colums where is no data in row 5.
And here comes my problem, when i want a xlmedium border around this new range it doesn't do what i want.
Al the edge's are xlmedium, except the edge on the far right (last column), this one is always xlthin.

How is this possible, when i selected the range within the code.

hope someone can help me.

Code:
Sub borders()

 Dim myBorders() As Variant, myBorders1() As Variant, myBorders2() As Variant, item As Variant
 myBorders = Array(xlEdgeLeft, xlEdgeTop, xlEdgeBottom, xlEdgeRight)
 myBorders1 = Array(xlInsideVertical, xlInsideHorizontal)
 myBorders2 = Array(xlDiagonalDown, xlDiagonalUp)

Application.ScreenUpdating = False

    sheets(Array("Jan", "Feb", "Mrt", "Apr", "Mei", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", _
        "Dec")).Select
    
    Union(Range(Cells(2, 2).End(xlToRight), Cells(19, 3)), Range(Cells(21, 3).End(xlToRight), Cells(38, 3))).Select
 
   For Each item In myBorders
    With Selection.Borders(item)
                  .LineStyle = xlContinuous
                  .ColorIndex = xlAutomatic
                  .Weight = xlMedium
    End With
Next item
    
   For Each item In myBorders1
    With Selection.Borders(item)
                  .LineStyle = xlContinuous
                  .ColorIndex = xlAutomatic
                  .Weight = xlThin
    End With
Next item
       
    For Each item In myBorders2
    With Selection.Borders(item)
                  .LineStyle = xlNone

    End With
Next item
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

Forum statistics

Threads
1,224,609
Messages
6,179,879
Members
452,948
Latest member
Dupuhini

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