Results 1 to 3 of 3

Thread: vba excel => passing a range

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    13

    vba excel => passing a range

    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 .

    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

  2. #2
    New Member
    Join Date
    May 2005
    Posts
    3

    Re: vba excel => passing a range

    Try to "call" the event

    => Call Worksheet_Change(r)

  3. #3
    Fanatic Member VBAhack's Avatar
    Join Date
    Dec 2004
    Location
    Sector 000
    Posts
    617

    Re: vba excel => passing a range

    I believe the following will also work:

    VB Code:
    1. Worksheet_Change r

    VBAhack

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width