View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
kounoike[_2_] kounoike[_2_] is offline
external usenet poster
 
Posts: 126
Default Help passing Range to Class Module method

I think it's because you use Function but not return value.

i change your code a little

' Class Module: "DowntimeReport"

Public Function PopulateByRange(R1 As Range) As Boolean

Dim MyRec As Range
On Error GoTo errhandle
For Each MyRec In R1
MyRec.Cells(1, 1).Interior.ColorIndex = 43
Next MyRec
'as Peter said, just the code below
'R1.Interior.ColorIndex = 43
'would do
PopulateByRange = True
Exit Function

errhandle:
PopulateByRange = False
End Function

' Module: "Kernel"

Sub KWTest()
Dim MyObj As Downtimereport
Set MyObj = New Downtimereport
Dim MyRng As Range
Dim result As Boolean

Set MyRng = Selection
With MyObj
'.PopulateByRange (ActiveSheet.Range("a1:b5"))
result = .PopulateByRange(MyRng)
If result Then
MsgBox "Method Succeeded"
Else
MsgBox "Method Failed"
End If
End With
End Sub

keiji

"Brian Herbert Withun" wrote in message
...
With MyObj
.PopulateByRange R1:=Selection


This did it! Thank you.


I would feel considerably less icky if I knew why that is different
from this:

.PopulateByRange (Selection)

for calls to this method:

Public Function PopulateByRange(R1 As Range) As Boolean
...