Vba all round border code

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,226
Office Version
  1. 2007
Platform
  1. Windows
Hi,
Can you advise please why the border around the whole cell isnt applied when i past a value please.


Rich (BB code):
    Target.Interior.Color = vbGreen
    Else
    Target.Interior.Color = vbRed
    End If
    With ActiveSheet.Range("E4:E28")
        .Font.Size = 11
        .Font.Bold = True
        .Font.Color = vbBlack
        .Font.Name = "Calibri"
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        Range("E4:E28").BorderAround xlContinuous, xlThin
        Range("E4:E28").NumberFormat = "@"
    End With
    Application.ScreenUpdating = True

End Sub
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
What happens if you just use
VBA Code:
Range("E4:E28").BorderAround xlContinuous
 
Upvote 0
Hi,

Same please see screen shot

I recorded a Macro which worked so can we make this code smaller.

VBA Code:
    Range("B12").Select
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlInsideVertical)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlInsideHorizontal)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    Range("B13").Select
End Sub
 

Attachments

  • 188.jpg
    188.jpg
    46.4 KB · Views: 7
Upvote 0
This did it.

Rich (BB code):
Range("B4:E28").Borders.LineStyle = xlContinuous
 
Upvote 0
Happy that you got a solution that works for you (although it isn't what I interpreted by your question i.e. border around).

Please note that the way you have it written you won't have the option of the weight and the linestyle. It is one or the other.
 
Upvote 0
Hi,
So does that mean we need to continue with another code and forget what i put above ?
 
Upvote 0
Hmmm
What ive done matches the others so i best leave it but thanks anyway.
 
Upvote 0
When using borders the default linestyle is xlcontinuous and the default weight is xlthin so in your case you could use any of the following
VBA Code:
Range("B4:E28").Borders.LineStyle = xlContinuous
Range("B4:E28").Borders.Weight = xlThin
Range("B4:E28").Borders.ColorIndex = 0

and you would get the same result.

You can also specify one change, for example
VBA Code:
Range("B4:E28").Borders.Weight = xlThick
and have no issues as the linestyle and color will use the defaults.

What you couldn't do is use the same syntax if you wanted 2 options different to the default. For example if you wanted a xlSlantDashDot linestyle and medium borders then you would have to use something like


Code:
    With Range("B4:E28")
        With .Borders
            .LineStyle = xlSlantDashDot
            .Weight = xlMedium
        End With
    End With

or with diagonals

VBA Code:
    With Range("B4:E28")
        With .Borders
            .LineStyle = xlSlantDashDot
            .Weight = xlMedium
        End With
        With .Borders(xlDiagonalDown)
            .LineStyle = xlSlantDashDot
            .Weight = xlMedium
        End With
        With .Borders(xlDiagonalUp)
            .LineStyle = xlSlantDashDot
            .Weight = xlMedium
        End With
    End With


Please note that
VBA Code:
Range("B4:E28").Borders.LineStyle = xlContinuous
does not change any diagonal borders, you have to set them separately if you ever need them (see code above).
 
Last edited:
Upvote 0
Thanks for this reply.
As you made the time to advise this I will now then use it.
Many thanks.

Do you have time to take a glance at my other post I’m working on.
At a point now where I’m stumped.

Thanks again.
 
Upvote 0

Forum statistics

Threads
1,214,924
Messages
6,122,294
Members
449,077
Latest member
Rkmenon

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