Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hope someone can help me with this... I'm a newbie.. so please understand... :)
I have an excel workbook that uses macros... I added a code each time there's a cell selection change. The code is simple as this:
Let sat I have a 3 work sheet... and a module
in each worksheet:Private Sub Worksheet_SelectionChange(ByVal Target As Range)
test (Sheet1)
End SubIN THE MODULE:
Public Sub test(whichSheet As Excel.Worksheet)
Select Case whichSheet
Case Sheet1:
MsgBox "sheet1"
Case Sheet2:
MsgBox "sheet2"
Case Sheet3:
MsgBox "sheet3"
End Select
End Sub
--- >IN EACH WORKSHEET THE PARAMETER OF THE TEST () SUBROUTINE CHANGES... DEPENDS ON THE WORKSHEET.. WS2 is test(Sheet2)...WS3 is test(Sheet3)...THE PROBLEM IS... I'm getting an ERROR 438
"object doesn't support this property or method"I'm doing this because I'll be having the same code for the 3 worksheets... PLEASE HELP... I CAN EMAIL YOU THE FILE IF SOMEONE NEEDS IT...
THANX
Ed

Looks like you're either trying to do something like place a string into an integer variable, or you're trying to retrieve a property from an object that doesn't support it.. E.G. You're trying to use 'Additem' on a textbox, or 'SelectionIndex' on a frame.. Try stepping into it (Debug > Step Into) and use the F8 key to scroll through the code, checking your variables in the locals window, and see exactly where the error pops up in the code.

Is that the exact code above?
When you say:
test(Sheet1)
First: You are calling a subroutine which requires parameters, so you need to use Call test(Sheet1)
Second: What is Sheet1? If you mean the sheet called Sheet1 then you should use Sheets("Sheet1") instead.
Third: Your Select Case doesn't work because you can't switch a 'Sheet'. You have to switch the sheet name, or some other aspect of the sheet. So you might, for example, change the select line to:
Select Case whichSheet.Name and then on the case lines, use quotes around Sheet1 etc.Finally, as a side thought: Do you need to pass a worksheet at all? If the 'test' function is called whenever you change your selection, then the Active worksheet will always be the same thing...
ie. Try changing your first routine to:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
test
End Suband your second to:
Public Sub test
MsgBox(ActiveSheet.Name)Select Case ActiveSheet.Name
Case "Sheet1":
'Sheet 1 routine here
Case "Sheet2":
'Sheet 2 routine here
Case "Sheet3":
'Sheet 3 routine here
End Select
End SubHope that gives you a 'leg-up'!!
Tom

![]() |
Linear Frame Buffer...
|
Expert systems in Prolog
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |