Click here to Skip to main content
15,789,952 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hy there

I'm a newby in coding with VBA. I searched alot for an answer for my problem, but couldn't find anything that helped me; maybe here I'm right.

I want to use the Worksheet_SelectionChange for a specific worksheet. This specific worksheet I want to define in the code

example (this example makes no sense, I know, but it is the best way to show my problem):

I have three worksheets in my workbook: ws1, ws2, ws3. ws1 and ws3 are empty, ws2 has some values.
When I open the workbook, I search wich worksheet is not empty. This works so far.
Now that I found wich worksheet is not empty, I want to set the Worksheet_SelectionChange for this worksheet.

How do I do this?

Thanks Guys
RedDk 17-Sep-13 15:50pm    
Ok, but you could help me by telling me what term/terms you used in this search named "alot".

Have you tried using the Excel Help found in the VBA interface "Excel (x) Developer Reference"? Also try typing into a module there the keywords that you find interesting and/or related to the problem, highlighting them, then hitting F1 on your keyboard. And finally, also in the VBA interface not the Excel mainframe, make sure the "Object Browser" is showing and type in causal words in the second box under "ALL Libraries". This could identify good candidates for testing vba code and almost always makes the whole inheritence scheme of methods and functions and all that good vba stuff more palatable.

Here[^] is a everything what you need to know ;) Please, read Application Events In A New Class Module section and modify code to your needs.
Share this answer
RedDk 17-Sep-13 16:00pm    
Ah yes!

It was great back in 1998!
Maciej Los 17-Sep-13 16:02pm    
I found the solution.

I need to put my code in THISWORKBOOK in a sub like this
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900