How to format borders to cells using VBA

Matador_24

Board Regular
Joined
Dec 1, 2011
Messages
205
Hello,

How can select a range of cells and apply a format to it using VBA?
For instance, let's say I want to take range B12 to D12 and remove all borders it has and then apply the border only to the top and bottom of the cell?
In the code, I need to specify that the row is a variable. My columns are always the same however the row is always different, thus, when I determine the range, I need to consider that the row will be a variable, for instance in my example above:
Lastrow = 12

Thanks!

Luis
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
You could try something like this.
Code:
Dim LastRow As Long

    LastRow = 12

    With Intersect(Rows(LastRow), Range("B:D"))
        .Borders.LineStyle = xlNone
        With .Borders(xlEdgeTop)
            .LineStyle = xlSingle
            .ColorIndex = 0
            .TintAndShade = 0
            .Weight = xlThick
        End With

        With .Borders(xlEdgeBottom)
            .LineStyle = xlSingle
            .ColorIndex = 0
            .TintAndShade = 0
            .Weight = xlThick
        End With

    End With
 
Upvote 0
Thanks, I will give it a try..... also, how do you set the color to the selection of cells?
I want a light blue, normally I tried this but did not work:

Code:
       .ThemeColor = xlThemeColorLight2
       .TintAndShade = 0.799981688894314
       .PatternTintAndShade = 0
[FONT=wf_segoe-ui_normal]
would you know how to specify color?

Thanks,

Luis[/FONT]
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,306
Members
452,633
Latest member
DougMo

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