Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Select a Range Through a Variable


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


--
GoFigure
------------------------------------------------------------------------
GoFigure's Profile: http://www.excelforum.com/member.php...fo&userid=4274
View this thread: http://www.excelforum.com/showthread...hreadid=490974

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Select a Range Through a Variable

Change

BorderRange = Chr(34) & Mid(str2, 1, _
(InStr(1, str2, ":") - 1)) & str1 & ":" _
& Mid(str2, (InStr(1, str2, ":") + 1), _
Len(str2)) & str1 & Chr(34)

to

BorderRange = Mid(str2, 1, _
(InStr(1, str2, ":") - 1)) & str1 & ":" _
& Mid(str2, (InStr(1, str2, ":") + 1), _
Len(str2)) & str1

in otherwords, lose the doublequote on each end.

--
Regards,
Tom Ogilvy


"GoFigure" wrote in
message ...

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


--
GoFigure
------------------------------------------------------------------------
GoFigure's Profile:

http://www.excelforum.com/member.php...fo&userid=4274
View this thread: http://www.excelforum.com/showthread...hreadid=490974



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 510
Default Select a Range Through a Variable

Hi

Try
ActiveSheet.Range(BorderRange).Select
or
Sheets(Sheetname).Range(BorderRange).Select


--
Arvi Laanemets
( My real mail address: arvil<attarkon.ee )


"GoFigure" wrote in
message ...

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


--
GoFigure
------------------------------------------------------------------------
GoFigure's Profile:
http://www.excelforum.com/member.php...fo&userid=4274
View this thread: http://www.excelforum.com/showthread...hreadid=490974



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Select a Range Through a Variable


Thanks, Tom and Arvi. I just modified the statement as Tom suggested.

Does Excel figure out that BorderRange is a string and that's why yo
don't have to form a double-quoted string?

- A

--
GoFigur
-----------------------------------------------------------------------
GoFigure's Profile: http://www.excelforum.com/member.php...nfo&userid=427
View this thread: http://www.excelforum.com/showthread.php?threadid=49097

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Select a variable range Bluecat Excel Worksheet Functions 7 January 13th 09 01:24 AM
Use a Variable to select a range Connie Excel Discussion (Misc queries) 3 October 19th 06 05:48 PM
How to assign a variable in a range select Paul Excel Programming 5 June 3rd 05 11:50 PM
Range("C9:V9").Select ==> changing the 9 to a variable B. F. Excel Worksheet Functions 8 May 23rd 05 01:16 PM
Range.Select with variable cells ? [email protected] Excel Programming 2 October 29th 03 08:43 PM


All times are GMT +1. The time now is 03:41 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"