Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 170
Default Newbie: problem referencing cell range between subs in the same mo

I try to use a cell range reference defined in one sub that call another sub
to change the border color of the cells in the the range. I get no errors,
but no border is painted.

Please explain why this doesn't work!

If I use the myRange.Select, I receive the error message: "Select Method of
Range class failed". How do I reference myRange in order to make it selected?
Should myRange be declared in the sub declaration, and not as a global
variable?

Regards

Frank Krogh

________________________

Private Sub MySub
With Worksheets("Sheet00")
Set myRange = .Range(.Cells( 27,7), .Cells( 27,8))
PaintBorder
end sub

Private Sub PaintBorder
With Worksheets("Sheet00")
myRange = Selection
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 5
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 5
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 5
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 5
End With
Selection.Borders(xlInsideVertical).LineStyle = xlNone
End With
End Sub

The module has this global range definition:
Dim myRange as Range




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 179
Default Newbie: problem referencing cell range between subs in the same mo

Change ur code"
myRange = Selection to myRange.Select

See updated code:

Dim myRange As Range
Private Sub MySub()
With Worksheets(1)
Set myRange = .Range(.Cells(27, 7), .Cells(27, 8))
PaintBorder
End With
End Sub

Private Sub PaintBorder()
With Worksheets(1)
myRange.Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 5
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 5
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 5
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 5
End With
Selection.Borders(xlInsideVertical).LineStyle = xlNone
End With
End Sub



"Frank" wrote:

I try to use a cell range reference defined in one sub that call another sub
to change the border color of the cells in the the range. I get no errors,
but no border is painted.

Please explain why this doesn't work!

If I use the myRange.Select, I receive the error message: "Select Method of
Range class failed". How do I reference myRange in order to make it selected?
Should myRange be declared in the sub declaration, and not as a global
variable?

Regards

Frank Krogh

________________________

Private Sub MySub
With Worksheets("Sheet00")
Set myRange = .Range(.Cells( 27,7), .Cells( 27,8))
PaintBorder
end sub

Private Sub PaintBorder
With Worksheets("Sheet00")
myRange = Selection
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 5
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 5
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 5
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 5
End With
Selection.Borders(xlInsideVertical).LineStyle = xlNone
End With
End Sub

The module has this global range definition:
Dim myRange as Range




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 170
Default Newbie: problem referencing cell range between subs in the sam

Thank you. I tried this also, but the range was not transferred.
So I tried Worksheets("Sheet00").Activate before myRange.Select, and then
it suddenly worked!


"Muhammed Rafeek M" wrote:

Change ur code"
myRange = Selection to myRange.Select

See updated code:

Dim myRange As Range
Private Sub MySub()
With Worksheets(1)
Set myRange = .Range(.Cells(27, 7), .Cells(27, 8))
PaintBorder
End With
End Sub

Private Sub PaintBorder()
With Worksheets(1)
myRange.Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 5
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 5
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 5
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 5
End With
Selection.Borders(xlInsideVertical).LineStyle = xlNone
End With
End Sub



"Frank" wrote:

I try to use a cell range reference defined in one sub that call another sub
to change the border color of the cells in the the range. I get no errors,
but no border is painted.

Please explain why this doesn't work!

If I use the myRange.Select, I receive the error message: "Select Method of
Range class failed". How do I reference myRange in order to make it selected?
Should myRange be declared in the sub declaration, and not as a global
variable?

Regards

Frank Krogh

________________________

Private Sub MySub
With Worksheets("Sheet00")
Set myRange = .Range(.Cells( 27,7), .Cells( 27,8))
PaintBorder
end sub

Private Sub PaintBorder
With Worksheets("Sheet00")
myRange = Selection
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 5
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 5
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 5
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 5
End With
Selection.Borders(xlInsideVertical).LineStyle = xlNone
End With
End Sub

The module has this global range definition:
Dim myRange as Range




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
Referencing a named range based upon Range name entry in cell Barb Reinhardt Excel Worksheet Functions 14 June 20th 07 07:19 PM
Referencing Row Range in another cell DJS Excel Discussion (Misc queries) 4 January 4th 07 01:12 AM
Newbie: VBA problem when copying cell range Frank Excel Programming 1 August 25th 06 01:33 PM
Referencing the First Cell in Any Selected Range maximouse Excel Programming 4 November 1st 05 03:57 AM
Newbie- Filename referencing in macros Ellen Excel Programming 5 August 27th 04 02:19 PM


All times are GMT +1. The time now is 10:32 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"