PDA

Click to See Complete Forum and Search --> : vba excel => passing a range


stt_d31
May 17th, 2005, 09:06 AM
Hello,

I have one simple worksheet and one simple command button on it.

In the code of the command button i specify a software coded range and and by clicking the command button, the worksheet_change function needs to explicitly executed with this range.

However, there seems to be an error by passing the range that i specified in the code of the command button.. I get the error 'runtime error 424', 'object required'.

can anyone tell me what's wrong with this simple piece of code .


Public Sub CommandButton1_Click()

Dim r As Range
Set r = Range("A1:B5")
Worksheet_Change (r)

End Sub

Public Sub Worksheet_Change(ByVal Target As Range)

MsgBox Target.Cells.Count

End Sub



thanks in advance

ipoxygen
May 17th, 2005, 10:19 AM
Try to "call" the event

=> Call Worksheet_Change(r)

VBAhack
May 17th, 2005, 02:05 PM
I believe the following will also work:

Worksheet_Change r

VBAhack