?
Solved

insert borders to a range that will change each time macro runs

Posted on 2014-10-15
5
Medium Priority
?
118 Views
Last Modified: 2014-10-16
I have been using the below code to insert borders but I need a varaition to this:

With ActiveSheet.UsedRange.Borders
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With

What I need to do is insert to the range I select, so if I say

Range(Range("B3"), Cells.SpecialCells(xlCellTypeLastCell)).Select

and the range is B3:J15 I just want borders around those cells

if range is B3:J58 I want borders around those cells.

I have tried to change ......With ActiveSheet.UsedRange.Borders
but have not been successful.

Could an Expert assist me please.

Many thanks
0
Comment
Question by:Jagwarman
[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
5 Comments
 
LVL 52

Expert Comment

by:Rgonzo1971
ID: 40381821
Hi,

pls try

Sub Mactro()
With ActiveSheet.UsedRange.Borders
    .LineStyle = xlNone
End With
Set myRange = Range(Range("B2"), Cells.SpecialCells(xlCellTypeLastCell))
With myRange.Borders(xlEdgeLeft)
    .LineStyle = xlContinuous
    .Weight = xlThin
    .ColorIndex = xlAutomatic
End With
With myRange.Borders(xlEdgeBottom)
    .LineStyle = xlContinuous
    .Weight = xlThin
    .ColorIndex = xlAutomatic
End With
With myRange.Borders(xlEdgeTop)
    .LineStyle = xlContinuous
    .Weight = xlThin
    .ColorIndex = xlAutomatic
End With
With myRange.Borders(xlEdgeRight)
    .LineStyle = xlContinuous
    .Weight = xlThin
    .ColorIndex = xlAutomatic
End With
   

End Sub

Open in new window

Regards
0
 
LVL 36

Accepted Solution

by:
Kimputer earned 2000 total points
ID: 40381823
As I don't have the full code, here are just some steps to point you in the right direction:

With Selection.Borders

Open in new window


or

With ActiveSheet.Range("B3:J58").Borders

Open in new window

(of course, try to make the range a variable, which you can set dynamically)
0
 

Author Comment

by:Jagwarman
ID: 40381833
Hi Rgonzo 1971 thanks for that, clearly you did what I asked and not what I wanted. Having read through my request again I did say "and the range is B3:J15 I just want borders around those cells" but what I meant was I want borders around every cell in that range. So once again I was not specific enough and got what I asked for. Sorry.
0
 

Author Closing Comment

by:Jagwarman
ID: 40381841
The first one is the one I need because I don't want to insert a range. Thanks
0
 

Expert Comment

by:Erick Wei
ID: 40386090
Try this one:

Sub test()

Call BorderLine(Sheet1.Range("B3:J15"))
Call BorderLine(Sheet1.Range("B3:J58"))

End Sub


Function BorderLine(rng As Range)

    With rng.Borders
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
   
End Function
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

752 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