ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Border problem with one row but no snag in many rows (https://www.excelbanter.com/excel-programming/309202-border-problem-one-row-but-no-snag-many-rows.html)

Hari[_3_]

Border problem with one row but no snag in many rows
 
Hi,

I have text from B3 to O3.

I recorded a macro to apply "All borders" in this range which I have pasted
below.

If I use the same macro for applying the same border style to some other one
row range like b4 to O4 then macro fails at each of the 3 lines following
"With Selection.Borders(xlInsideHorizontal)"

If I use the same macro for applying the all border to more than one row
range then the macro doesnt fail.

Why?. Surprising thing is the macro itself was recorded based on one row
selection then why is it that it fails inspite of having the same starting
conditions for the macro

Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With


Regards,
Hari
India



mangesh_yadav[_110_]

Border problem with one row but no snag in many rows
 
When you recorded the macro by selecting only one row, you msut hav
clicked on the menu for putting borders. Here by default excel too
care not to give error. But when you try to use the same for a one-ro
range, the macro fails as it cannot find the inside horizantal elemen
for the range. This is an expected behaviour.

manges

--
Message posted from http://www.ExcelForum.com


mangesh_yadav[_109_]

Border problem with one row but no snag in many rows
 
When you recorded the macro by selecting only one row, you must hav
clicked on the menu for putting borders. Here by default excel too
care not to give error. But when you try to use this macro for anothe
one-row range, the macro fails as it cannot find the inside horizanta
element for the range. This is an expected behaviour.

manges

--
Message posted from http://www.ExcelForum.com


Hari[_3_]

Border problem with one row but no snag in many rows
 
Hi Mangesh,

Thanx a lot. That was definitely informative.

I have changed it to do the all border way only when there is more than one
row and in one row case I will skip the inside horizontal element.

Thanx again.

Regards,
Hari
India

"mangesh_yadav " wrote in
message ...
When you recorded the macro by selecting only one row, you msut have
clicked on the menu for putting borders. Here by default excel took
care not to give error. But when you try to use the same for a one-row
range, the macro fails as it cannot find the inside horizantal element
for the range. This is an expected behaviour.

mangesh


---
Message posted from http://www.ExcelForum.com/





All times are GMT +1. The time now is 05:11 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com