LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #8   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Can Worksheet_Change run from separate module?

Yep.

But I would want the test to ignore upper/lower case:

if lcase(sh.name) < lcase("mysheet") then

And you'll want to qualify that range:

if intersect(target, sh.range("myRange")) is nothing then

====
As for benefits...

If the code is almost the same in 20 worksheets (but different in 2), then using
the workbook_sheetchange with those checks seems much more efficient (for the
developer).

If the code isn't the same--or the sheet has to be copied to a different
workbook--with the code intact, then using the worksheet_change event seems
better.



Horatio J. Bilge, Jr. wrote:

Jim's suggestion is working well, but if I were to use the
Workbook_SheetChange event, would I just test the sheet name first, and then
the target?
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Sh.Name < "MySheet" Then
Exit Sub
End If
' then something like...
If Application.Intersect(Target, Range("MyRange")) Is Nothing Then
' rest of code here
End Sub

Are there benefits to using one method over the other?

~ Horatio

"Dave Peterson" wrote:

You may want to see if you could use the Workbook_SheetChange event.



Horatio J. Bilge, Jr. wrote:

I have a worksheet ("MySheet") with about 300 lines of code in the
Worksheet_Change event. When a user opens the workbook, MySheet will be
copied as many times as the user indicates (maybe up to 30-40 times). As a
result, my 300 lines of code goes up to about 12,000 lines.

I am wondering if it is possible to put the code into a separate module, and
then use the Worksheet_Change event to call the code from that other module.

~ Horatio


--

Dave Peterson


--

Dave Peterson
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
CLASS MODULE & SIMPLE MODULE FARAZ QURESHI Excel Discussion (Misc queries) 1 September 7th 07 09:32 AM
Worksheet_Change scrimmy Excel Discussion (Misc queries) 7 April 26th 07 12:12 PM
code in module A to not execute a Worksheet_SelectionChange sub of another module Jack Sons Excel Discussion (Misc queries) 4 December 11th 05 11:52 PM
Getting around Worksheet_Change() mtowle Excel Worksheet Functions 1 October 20th 05 06:05 PM
Worksheet_change won't run Eric Excel Discussion (Misc queries) 4 March 10th 05 03:43 PM


All times are GMT +1. The time now is 10:01 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"