Solved

VBA borders around all cells

Posted on 2013-11-25
7
9,096 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
7 Comments
 
LVL 48

Assisted Solution

by:Rgonzo1971
Rgonzo1971 earned 125 total points
Comment Utility
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 45

Assisted Solution

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

Expert Comment

by:zorvek (Kevin Jones)
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 43

Assisted Solution

by:Saqib Husain, Syed
Saqib Husain, Syed earned 125 total points
Comment Utility
Try

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

Accepted Solution

by:
zorvek (Kevin Jones) earned 125 total points
Comment Utility
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
0
 

Author Comment

by:Frank Freese
Comment Utility
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
Comment Utility
thank you to all
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directi…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now