G
GoFigure
Excel ver: 2003 [11 (SP2)]
OS: WXP (SP2)
In the following code, VBA returns the error "Method 'Range' of
object'_Global' failed" at the statement Range(BorderRange).Select.
Code:
--------------------
Dim PageBorderRows, TotalBorderCells, RestoreBorderCells
Dim str1 As Variant, str2 As Variant, BorderRange
PageBorderRows = Array("53", "96")
TotalBorderCells = Array("K:L", "V:W", "AG:AH")
For Each str1 In PageBorderRows
For Each str2 In TotalBorderCells
BorderRange = Chr(34) & Mid(str2, 1, (InStr(1, str2, ":") - 1)) & str1 & ":" _
& Mid(str2, (InStr(1, str2, ":") + 1), Len(str2)) & str1 & Chr(34)
Range(BorderRange).Select
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
Next ' TotalBorderCells
Next ' PageBorderRows
--------------------
How can I create a named range in this manner and use it to select that
range?
For example, the first pass through the code results in the range
"K53:L53". But Range(BorderRange).Select produces the above error.
Thanks,
- Al
OS: WXP (SP2)
In the following code, VBA returns the error "Method 'Range' of
object'_Global' failed" at the statement Range(BorderRange).Select.
Code:
--------------------
Dim PageBorderRows, TotalBorderCells, RestoreBorderCells
Dim str1 As Variant, str2 As Variant, BorderRange
PageBorderRows = Array("53", "96")
TotalBorderCells = Array("K:L", "V:W", "AG:AH")
For Each str1 In PageBorderRows
For Each str2 In TotalBorderCells
BorderRange = Chr(34) & Mid(str2, 1, (InStr(1, str2, ":") - 1)) & str1 & ":" _
& Mid(str2, (InStr(1, str2, ":") + 1), Len(str2)) & str1 & Chr(34)
Range(BorderRange).Select
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
Next ' TotalBorderCells
Next ' PageBorderRows
--------------------
How can I create a named range in this manner and use it to select that
range?
For example, the first pass through the code results in the range
"K53:L53". But Range(BorderRange).Select produces the above error.
Thanks,
- Al