tiddle.co.uk:
I literally just fixed a bug that has plagued me for the last few days. I originally wrote the code using the terrible reference literature for Excel 03. The issue is actually that the index it tells you to use doesn’t exist! The text below is taken from the Borders object page, specifically relating to FormatConditions (the conditional formatting object) and is wrong:
Use Borders(index), where index identifies the border, to return a single Border object. The following example sets the color of the bottom border of cells A1:G1 to red.
Worksheets("Sheet1").Range("A1:G1"). _
Borders(xlEdgeBottom).Color = RGB(255, 0, 0)
Index can be one of the following XlBordersIndex constants: xlDiagonalDown, xlDiagonalUp, xlEdgeBottom, xlEdgeLeft, xlEdgeRight, or xlEdgeTop, xlInsideHorizontal, or xlInsideVertical.
I was trying to apply formatting to the bottom border, so obviously I used xlEdgeBottom, and hence continually received the aforementioned runtime error. After what seems like hours of [non-sequential] Googling, I found a post where someone was doing something similar enough to me, successfully, to learn from it. Almost immediately I saw the difference; their chosen indexes did not contain “Edge”. I removed them from my code, and voila it works perfectly, all errors were gone and the sheet formats beautifully.
Ok, so I probably should have found a better reference to the object library, but the Microsoft online one is no better or easier to use than the offline one, which coincidently loads faster! On a similar note, if you’ve ever looked up an error code to find a bug solution page by Microsoft, you’ll know the wide range of issues and limitations of their software that intersect in very weird ways. Surprising the main application runs really! I hope someone finds this and it helps them, as otherwise I just wasted time documenting this !
Mutatom, hogy néznek ki az emlegetett konstansok:
?xlEdgeLeft, xlLeft 7 -4131 ?xlEdgeTop, xlTop 8 -4160 ?xlEdgeRight, xlRight 10 -4152 ?xlEdgeBottom, xlBottom 9 -4107
Sub setBorder(ByVal myRange As Range, ByVal borderArray As Variant) ' call setBorder(Selection, array(array(xlEdgeTop, xlthick, xlContinuous))) Dim i As Long, j As Long For i = LBound(borderArray) To UBound(borderArray) With myRange.Borders(borderArray(i)(0)) .LineStyle = xlLineStyleNone .LineStyle = borderArray(i)(2) .Weight = borderArray(i)(1) End With Next i End Sub