[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

VBA borders around all cells

Posted on 2013-11-25
7
Medium Priority
?
17,678 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 53

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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

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

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
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 demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

650 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