ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   help!!! i can not send target to my sub in event (https://www.excelbanter.com/excel-programming/291372-help-i-can-not-send-target-my-sub-event.html)

benbenben

help!!! i can not send target to my sub in event
 
i dim a sub named test(r as range)
And I call this sub in the worksheet_selectionchange event as below
But the VB stop it with error messege .said , it need a object
how can i solve it?
pls help me
the program is below:

Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
test(activework.sheets("sheet1").range("A1:B2"))
'this sentense work
test (Target)
'this sentense doesnt work
End Sub

Sub test(r As Range)
MsgBox "OK"
End Sub

help would be appreciate

--
Message posted from http://www.ExcelForum.com


Rob van Gelder[_4_]

help!!! i can not send target to my sub in event
 
You don't need the brackets, unless you're using the Call statement.

Also, it's ActiveWorkbook, not ActiveWork

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
test ActiveWorkbook.Sheets("sheet1").Range("A1:B2")
test Target
End Sub

Sub test(r As Range)
MsgBox "OK"
End Sub


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"benbenben " wrote in message
...
i dim a sub named test(r as range)
And I call this sub in the worksheet_selectionchange event as below
But the VB stop it with error messege .said , it need a object
how can i solve it?
pls help me
the program is below:

Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
test(activework.sheets("sheet1").range("A1:B2"))
'this sentense work
test (Target)
'this sentense doesnt work
End Sub

Sub test(r As Range)
MsgBox "OK"
End Sub

help would be appreciated


---
Message posted from http://www.ExcelForum.com/





All times are GMT +1. The time now is 07:28 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com