Cell bordering

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi All,

I have a range (A22:A95) which has a left and right cell border.
The right cell border gets changed by other macros.
What im trying to do, is set the right border the same as left border for
each cell in the selection. Below is the code i currently have:

---------------------------------------------------------

Dim c As Range
For Each c In Selection
With c.Borders(xlEdgeLeft)
CellThickness = c.Borders.Weight
CellColorIndex = c.Borders.ColorIndex
End With
With c.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = CellThickness
.ColorIndex = CellColorIndex
End With
Next c

------------------------------------------
This code changes the right border but not to the same as the left. I.e. it
puts the line as dotted, and if the left side of the cell has a border, and
if the left side is blank, it puts in a think line on the right side of the
cell.

Can anyone please asist.

Cheers.
Al.
 
See if it works correctly this way:

Dim c As Range
For Each c In Selection
With c.Borders(xlEdgeLeft)
CellThickness = .Weight
CellColorIndex = .ColorIndex
End With
With c.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = CellThickness
.ColorIndex = CellColorIndex
End With
Next c
 
Thanks Myrna,

Didn't really register that i was referencing the cell twice.

Al.
 
Actually you were defeating the purpose of the

With c.Borders(xlEdgeLeft)

and looking at the properties of the entire borders collection. It could be
that (I haven't checked), since the borders aren't all the same, the property
is returning Null.
 

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

Back
Top