?
Solved

VBA borders around all cells

Posted on 2013-11-25
7
Medium Priority
?
15,916 Views
Last Modified: 2013-11-25
Folks,
I am looking for a way to add borders around all cells using VBA for the range K3:L13. What I tried below doesn't seem to even give me the bottom edge.

Range("K3:L13").Borders(xlEdgeBottom).LineStyle = XlLineStyle.xlContinuous

Open in new window

0
Comment
Question by:Frank Freese
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 52

Assisted Solution

by:Rgonzo1971
Rgonzo1971 earned 500 total points
ID: 39674957
Hi,

pls try

Sub Macro7()
'
' Macro7 Macro
'

'
Set myrange = Range("K13:L13")
    myrange.Borders(xlDiagonalDown).LineStyle = xlNone
    myrange.Borders(xlDiagonalUp).LineStyle = xlNone
    With myrange.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With myrange.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With myrange.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With myrange.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With myrange.Borders(xlInsideVertical)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With myrange.Borders(xlInsideHorizontal)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
End Sub

Open in new window

Regards
0
 
LVL 49

Assisted Solution

by:Martin Liss
Martin Liss earned 500 total points
ID: 39674958
If you can do it by hand, record a macro while you are doing it.
0
 
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
ID: 39674965
When working with multiple rows at the same time you have to set the inside horizontal border:

Range("K3:L13").Borders(xlEdgeBottom).LineStyle = XlLineStyle.xlContinuous
Range("K3:L13").Borders(xlInsideHorizontal).LineStyle = XlLineStyle.xlContinuous

Kevin
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 43

Assisted Solution

by:Saqib Husain, Syed
Saqib Husain, Syed earned 500 total points
ID: 39674969
Try

Range("K3:L13").Borders(xlEdgeBottom).LineStyle = xlContinuous
0
 
LVL 81

Accepted Solution

by:
zorvek (Kevin Jones) earned 500 total points
ID: 39674982
Here is an elegant method for setting the borders around all individual cells in a multiple cell range:

   Dim BorderIndex As Variant
   For Each BorderIndex In Array(xlEdgeTop, xlEdgeLeft, xlEdgeBottom, xlEdgeRight, xlInsideHorizontal, xlInsideVertical)
      With TargetRange.Borders(BorderIndex)
         .Weight = xlThin
         .ColorIndex = xlAutomatic
      End With
   Next BorderIndex

In your case replace TargetRange with Range("K3:L13").

Kevin
1
 

Author Comment

by:Frank Freese
ID: 39675037
Folks,
I wrote this and it worked! Surprised even myself.

Dim rng As Range
    Set rng = Range("K3:L13")
    With rng.Borders
        .LineStyle = xlContinuous
        .Color = vbBlack
        .Weight = xlThin
    End With

In fairness to all I'll distribute the points the points equally. I appreciate your response
0
 

Author Closing Comment

by:Frank Freese
ID: 39675048
thank you to all
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question