LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Help passing Range to Class Module method

I am attempting to instantiate a user defined object (a Class Module)
and then pass a range of cells to that object by calling one of its
methods.

This is what I have so far:

'==================
' Class Module: "DowntimeReport"

Option Explicit

' this is intended to be an object method
Public Function PopulateByRange(R1 As Range) As Boolean

Dim MyRec As Range

For Each MyRec In R1
MyRec.Cells(1, 1).Interior.ColorIndex = 43
Next MyRec

End Function

'==================
' Module: "Kernel"

' this is just a VB Macro
Sub KWTest()
Dim MyObj As DowntimeReport
Set MyObj = New DowntimeReport
Dim MyRng As Range
Set MyRng = Selection
With MyObj
.PopulateByRange (ActiveSheet.Range("B2:F44"))
'.PopulateByRange (MyRng)
End With
End Sub

'==================

This works as written, and it changes the background color of cells
B2:F44

What I would like to have it do is change the background color of the
Selection, not just a hard-coded range of cells. If I uncomment the
line above (.PopulateByRange(MyRng)) it fails with "Object Required."

How can I pass the active selection as a range to my method
PopulateByRange() ?

In case it matters, I am initiating this by assigning the macro
"KWTest" to a custom button on a custom toolbar. I select a range of
cells and the press the custom button.

Brian Herbert Withun
 
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 method of Range class failed Capo Excel Programming 4 August 9th 06 04:27 PM
Select method of range class failed sa02000[_4_] Excel Programming 1 October 5th 05 01:20 PM
What did I do? (Select Method of Range Class Failed ) HotRod Excel Programming 9 May 20th 05 02:11 PM
Delete method of Range class failed - HELP!!! richilli Excel Programming 1 October 20th 04 06:24 PM
Calling a module function from a class method ranafout[_2_] Excel Programming 1 November 12th 03 11:08 AM


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

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

About Us

"It's about Microsoft Excel"