Adding Horizontal and/or Vertical borders with VBA.

cr130

New Member
Joined
Oct 3, 2023
Messages
15
Office Version
  1. 2016
Platform
  1. Windows
Hello All,

I am using a code that the awesome @HighAndWilder helped me with but I needed a little more assistance.

To set the premise, I wanted to have E4:F11 hidden when the checkbox is unchecked and when it is checked to have the cells visible and formatted (which that does work but need a little more).

The first thing is this code creates a border around the range, which I do want but I was wondering if there was a way to do horizontal and/or vertical borders on a certain range. For example on the screen shot below, I would want thin borders on the bottom of E5:F5, bottom of E7:F7 and the bottom of E9:F9 and still keep the thick borders on the whole range (E4:F11).

Second thing; with the code below, I was wondering if there was a way to only change the colors of some of the cells. For instance on this screenshot I would want E5,E7, E9, and E11 white filled(the rest the red color).

I am using ActiveX Checkboxes and ActiveX buttons on other parts of the sheet. this is for work so i cant upload the sheet but I can answer more questions and upload more screenshots if needed. I am still very new to using VBA and ActiveX controls so I would appreciate the help!

Excel Formula:
[/HEADING]
Private Sub CheckBox5_Click()
   With ActiveSheet
      If .Range("E4").Interior.Color = vbWhite Then
        
        With .Range("E4:E11", "F5:F11")
          .Interior.Color = RGB(220, 86, 65)
          .Font.Color = RGB(0, 0, 0)
        End With
      
        Range("E4:E11", "F5:F11").BorderAround _
          LineStyle:=xlContinuous, _
          Weight:=xlThick, _
          Color:=RGB(0, 0, 0)
      
      Else
      
        With .Range("E4:E11", "F5:F11")
          .Font.Color = RGB(255, 255, 255)
          .Interior.ColorIndex = xlNone
          With .Borders
            .LineStyle = xlNone
          End With
        End With
      
      End If
  
    End With
End Sub
[HEADING=3]


1700168931260.png
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

Forum statistics

Threads
1,224,820
Messages
6,181,159
Members
453,021
Latest member
Justyna P

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