Borders(xlLeft)

  • Thread starter Thread starter Mark Worthington
  • Start date Start date
M

Mark Worthington

Having recently got in a twizz regarding xlPasteColumnWidths vs
xlColumnWidths, I have now come across something similar. Old macros
that I create some time ago use the following :

Selection.Borders(xlLeft)

As I'm trying to understand what is going on, I looked in VBA Help,
only to find refrences to the relevant following XlBordersIndex
constant, xlEdgeLeft.

Just to put things in their place, can anyone advise whether this
matters and what is the correct Index to use with the Border object.

Cheers,

Mark
 
Mark,

xlLeft = -4131 and xlEdgeLeft = 7, so for borders you want to use
xlEdgeLeft.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
Chip,

Advice taken, but I don't understand this : I select any number of
cells, then :

My old code using xlLeft :

With Selection.Borders(xlLeft)
.LineStyle = xlContinuous
.Weight = xlMedium
.Color = RGB(0, 0, 0)
End With

will border each and every selected cell.

New code using xlEdgeLeft :

With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlMedium
.Color = RGB(0, 0, 0)
End With

Will border only the left edge (obviously).

Is the xlLeft something from by-gone days, say Excel 97, because I can
find no references to it in Help?

Cheers,

Mark
 
Mark,

The two snippets of code seem to do exactly the same thing. I
suspect that xlLeft is left over from previous versions of Excel,
having been replaced with other constants with the same value,
such as xlSummaryOnLeft, xlLegendPositionLeft, and xlAlignLeft.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
Chip,

Not quite.

If you select 9 cells, say a 3x3, then Borders(XlLeft) will not only
border the leftmost 3 cells, but also the other 2 columns of cells, too.

Borders(xlEdgeLeft) will ONLY border the leftmost 3 cells. To do the
same job as above, you need to also apply Borders(xlInsideVertical) to
the 3x3 selection.

This raises the general question with Excel : is it wise to carry on
using what appears to be an undocumented constant which does the job of
2 "latest" ones .... or apply the new constants as and when they become
current?

It's like vbCrLf, vbCr, vbLf, vbNewLine ... I use the last one as it
makes more sense to me ... I suppose there's no absolute right or wrong.

Regards,

Mark
 
Back
Top