Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 489
Default Set Range with Long Variable

I have 3 ranges I want to add vertical lines too, but I keep getting an error
that says "Wrong Number of Arguements or Invalid Property Assignment."
Anyone know why? Is there a cleaner way to write out this range?

Sub AddLines()

Dim lngFirstRow As Long
Dim lngLastRow As Long

' adds thin vertical lines to separate columns
With Range("B" & lngFirstRow & ":B" & lngLastRow, _
"F" & lngFirstRow & ":F" & lngLastRow, _
"H" & lngFirstRow & ":H" & lngLastRow)
.Borders(xlEdgeLeft).Weight = xlThin
.Borders(xlEdgeRight).Weight = xlThin
End With

End Sub
--
Cheers,
Ryan
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default Set Range with Long Variable

Ryan,
see if this helps:

Sub AddLines()

Dim lngFirstRow As Long
Dim lngLastRow As Long

Dim MultiRange As Range


Set MultiRange = Union(Range("B" & lngFirstRow & ":B" & lngLastRow), _
Range("F" & lngFirstRow & ":F" &
lngLastRow), _
Range("H" & lngFirstRow & ":H" & lngLastRow))


' adds thin vertical lines to separate columns
With MultiRange

.Borders(xlEdgeLeft).Weight = xlThin

.Borders(xlEdgeRight).Weight = xlThin

End With



End Sub
--
jb


"Ryan H" wrote:

I have 3 ranges I want to add vertical lines too, but I keep getting an error
that says "Wrong Number of Arguements or Invalid Property Assignment."
Anyone know why? Is there a cleaner way to write out this range?

Sub AddLines()

Dim lngFirstRow As Long
Dim lngLastRow As Long

' adds thin vertical lines to separate columns
With Range("B" & lngFirstRow & ":B" & lngLastRow, _
"F" & lngFirstRow & ":F" & lngLastRow, _
"H" & lngFirstRow & ":H" & lngLastRow)
.Borders(xlEdgeLeft).Weight = xlThin
.Borders(xlEdgeRight).Weight = xlThin
End With

End Sub
--
Cheers,
Ryan

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Set Range with Long Variable

Here is shorter way to write that Set statement for the MultiRange
variable...

Set MultiRange = Intersect(Rows(lngFirstRow & ":" & _
lngLastCol), Range("B:B,F:F,H:H"))

--
Rick (MVP - Excel)


"john" wrote in message
...
Ryan,
see if this helps:

Sub AddLines()

Dim lngFirstRow As Long
Dim lngLastRow As Long

Dim MultiRange As Range


Set MultiRange = Union(Range("B" & lngFirstRow & ":B" & lngLastRow), _
Range("F" & lngFirstRow & ":F" &
lngLastRow), _
Range("H" & lngFirstRow & ":H" &
lngLastRow))


' adds thin vertical lines to separate columns
With MultiRange

.Borders(xlEdgeLeft).Weight = xlThin

.Borders(xlEdgeRight).Weight = xlThin

End With



End Sub
--
jb


"Ryan H" wrote:

I have 3 ranges I want to add vertical lines too, but I keep getting an
error
that says "Wrong Number of Arguements or Invalid Property Assignment."
Anyone know why? Is there a cleaner way to write out this range?

Sub AddLines()

Dim lngFirstRow As Long
Dim lngLastRow As Long

' adds thin vertical lines to separate columns
With Range("B" & lngFirstRow & ":B" & lngLastRow, _
"F" & lngFirstRow & ":F" & lngLastRow, _
"H" & lngFirstRow & ":H" & lngLastRow)
.Borders(xlEdgeLeft).Weight = xlThin
.Borders(xlEdgeRight).Weight = xlThin
End With

End Sub
--
Cheers,
Ryan


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
http://CannotDeleteFile.net - Cannot Delete File? Try Long Path ToolFilename is too long? Computer Complaining Your Filename Is Too Long? TheLong Path Tool Can Help While most people can go about their businessblissfully unaware of the Windo Max Loger Excel Discussion (Misc queries) 0 June 14th 11 04:30 PM
Can't insert a String Variable of Long Date into Page Header Ronny Hamida Excel Programming 3 April 18th 06 05:43 PM
setting a range variable equal to the value of a string variable Pilgrim Excel Programming 2 July 1st 04 11:32 PM
Loop a long formula through range hotherps[_44_] Excel Programming 2 April 13th 04 11:46 PM
Problem trying to us a range variable as an array variable TBA[_2_] Excel Programming 4 September 27th 03 02:56 PM


All times are GMT +1. The time now is 03:02 PM.

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"