beks123
beks123

Reputation: 55

Changing borders and linestyles around various ranges in vba

my table now

[what I want my table to look like[2]

I am trying to get a proper border around my table, but everytime I try to make it around certain ranges based on color, it comes out as dotted lines. I want solid lines, but nothing I seem to do to the linestyle works. I also don't want the black vertical lines within the red boxes, but it was the only way to get the line solid not dashed. The first picture I attached is what mine looks like, and the second is what I want mine to look like. Here is the code I've been using as well:

Sub borders()
'
' borders and colors
'

'
'B column = blue

   range("B2:B46, D2:D6").Select
   Selection.BorderAround
    With Selection.Interior

        .Color = 6108951

    End With

    'C column = gray

   range("C2:C6").Select
   With Selection.borders(xlLeft)
    .Weight = xlThin
   End With
   With Selection.borders(xlRight)
   .Weight = xlThin
   End With

   With Selection.Interior
    .Color = 12632256
    End With


   range("C7:C46").Select
   Selection.borders.LineStyle = xlContinuous
   With Selection.Interior
    .Color = 12632256
    End With

    'thin columns = gray
   range("E2:E46, I2:I46, M2:M46, Q2:Q46, U2:U46, Y2:Y46, AC2:AC46, AG2:AG46, AK2:AK46, AO2:AO46, AS2:AS46").Select
    Selection.BorderAround (xlThin)
   Selection.borders.LineStyle = xlContinuous
   With Selection.Interior
    .Color = 11711154
    End With

  'rows gray
    range("B21, B36, B43, B46").Select
    With Selection.Interior
    .Color = 12632256
   End With

'categories gray

range("D7:D45").Select
Selection.borders.LineStyle = xlContinuous

 With Selection.Interior
 .Color = 15395562
  End With

   'red rows
   range("C21:AS21, C36:AS36, C43:AS43, C46:AS46").Select
    Selection.BorderAround (xlThin)
   Selection.borders.LineStyle = xlContinuous
   'Selection.Border -Style: Solid
       With Selection.Interior
        .Color = 128
     End With


     'outside thick border

range("B2:AX46").Select
   Selection.BorderAround , Weight:=xlThick


   'border around trigger, weight, limit
   range("AU5:AW20").Select
    Selection.borders.LineStyle = xlContinuous

    range("AU5:AW6").Select
    Selection.borders.LineStyle = xlNone
    Selection.BorderAround (xlThin)




   End Sub

Upvotes: 0

Views: 9871

Answers (1)

RGA
RGA

Reputation: 2607

Maybe try making it all one call, so

'thin columns = gray
   range("E2:E46, I2:I46, M2:M46, Q2:Q46, U2:U46, Y2:Y46, AC2:AC46, AG2:AG46, AK2:AK46, AO2:AO46, AS2:AS46").Select
    Selection.BorderAround Weight:=xlThin, LineStyle:= xlContinuous
   With Selection.Interior
    .Color = 11711154
    End With

Upvotes: 2

Related Questions