Borders within a With/End With

O

Otto Moehrbach

Excel XP & Win XP
I have the following code to place a black thin border around every cell in
the range, and a thick colored border around (outline) the whole range. I
get an error "Object Required" on the first line and would probably get the
same error on the second line if the code got past the first line. What is
the proper syntax/code to do what I want? Thanks for your time. Otto
With ws
.["F1:H6"].Borders LineStyle:=xlContinuous, Weight:=xlThin,
ColorIndex:=xlAutomatic
.["F1:H6"].BorderAround LineStyle:=xlContinuous,
Weight:=xlThick, ColorIndex:=9
.["F1:H6"].Interior.ColorIndex = 36
End With
 
J

Jon Peltier

First, I wouldn't use ["F1:H6"] (or any of the [] shorthand), but
Range("F1:H6"). The shorthand is sometimes convenient, sometimes confusing
and misleading, and sometimes makes it hard to track down a problem.

Second, I think what you need is
With ws
With .Range("F1:H6").Borders
.LineStyle=xlContinuous
.Weight=xlThin
.ColorIndex:=xlAutomatic
End With
' etc.
End With

- Jon
 
O

Otto Moehrbach

Thanks Jon. I'll give that a try. Otto
Jon Peltier said:
First, I wouldn't use ["F1:H6"] (or any of the [] shorthand), but
Range("F1:H6"). The shorthand is sometimes convenient, sometimes confusing
and misleading, and sometimes makes it hard to track down a problem.

Second, I think what you need is
With ws
With .Range("F1:H6").Borders
.LineStyle=xlContinuous
.Weight=xlThin
.ColorIndex:=xlAutomatic
End With
' etc.
End With

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
http://PeltierTech.com
_______


Otto Moehrbach said:
Excel XP & Win XP
I have the following code to place a black thin border around every cell
in the range, and a thick colored border around (outline) the whole
range. I get an error "Object Required" on the first line and would
probably get the same error on the second line if the code got past the
first line. What is the proper syntax/code to do what I want? Thanks for
your time. Otto
With ws
.["F1:H6"].Borders LineStyle:=xlContinuous, Weight:=xlThin,
ColorIndex:=xlAutomatic
.["F1:H6"].BorderAround LineStyle:=xlContinuous,
Weight:=xlThick, ColorIndex:=9
.["F1:H6"].Interior.ColorIndex = 36
End With
 
A

Alok

Hi Otto,
What you tried implies that Borders is a method. In fact it is a collection.
Try
With Range("A1:B6").Borders
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top