Computing.Net > Forums > Programming > VB and EXCEL HELP

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

VB and EXCEL HELP

Reply to Message Icon

Name: edgar
Date: July 21, 2002 at 10:42:12 Pacific
Comment:

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 Sub

IN 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



Sponsored Link
Ads by Google

Response Number 1
Name: TobyR
Date: July 21, 2002 at 13:20:12 Pacific
Reply:

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.


0

Response Number 2
Name: A Certain TH
Date: July 22, 2002 at 01:49:22 Pacific
Reply:

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 Sub

and 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 Sub

Hope that gives you a 'leg-up'!!

Tom


0

Response Number 3
Name: ed
Date: July 22, 2002 at 19:28:44 Pacific
Reply:

THANX GUYS!!


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Linear Frame Buffer... Expert systems in Prolog



Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: VB and EXCEL HELP

vb and excel www.computing.net/answers/programming/vb-and-excel/9828.html

VB and string delimiters www.computing.net/answers/programming/vb-and-string-delimiters/6176.html

VB and MAPI - a basic question www.computing.net/answers/programming/vb-and-mapi-a-basic-question/3329.html