Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Plase help me clean up my code

On a worksheet, I have a whole series of related commands that launc
when the user clicks in one of four ranges of cells. WHat thos
commands are is unimportant. Suffice to say each set of VBA code fo
each of the four ranges of cells is a long series of code.

Right now, I have all four sections in one large module. I want t
create a separate sub-routine for each of the four sections, but
don't know how to do it (all efforts result in error).

The catch is that all of the commands stem from the user clicking in
given cell. Thus the sub starts with:

________
Private Sub Worksheet_SelectionChange(ByVal target As Range)

[Long code regarding range 1 of cells]

[Long code regarding range 2 of cells]

[Long code regarding range 3 of cells]

[Long code regarding range 4 of cells]
End sub
____________



What I want is the following:


________
Private Sub Worksheet_SelectionChange(ByVal target As Range)

[If user selects one cell in the range A1:A50 then call sub1]


[If user selects one cell in the range B1:B50 then call sub2]


[If user selects one cell in the range C1:CA50 then call sub3]


[If user selects one cell in the range D1:D50 then call sub4]


End sub

____________


Suggestions??

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Plase help me clean up my code

Jason ,

Try this

Private Sub Worksheet_SelectionChange(ByVal target As Range)

If Not Intersect (Target, Range("A1:A50")) Is Nothing Then
sub1
ElseIf Not Intersect (Target, Range("B1:B50")) Is Nothing Then
sub2
ElseIf Not Intersect (Target, Range("C1:C50")) Is Nothing Then
sub3
ElseIf Not Intersect (Target, Range("D1:D50")) Is Nothing Then
sub4
End If

End sub



--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"jasonsweeney " wrote in
message ...
On a worksheet, I have a whole series of related commands that launch
when the user clicks in one of four ranges of cells. WHat those
commands are is unimportant. Suffice to say each set of VBA code for
each of the four ranges of cells is a long series of code.

Right now, I have all four sections in one large module. I want to
create a separate sub-routine for each of the four sections, but I
don't know how to do it (all efforts result in error).

The catch is that all of the commands stem from the user clicking in a
given cell. Thus the sub starts with:

________
Private Sub Worksheet_SelectionChange(ByVal target As Range)

[Long code regarding range 1 of cells]

[Long code regarding range 2 of cells]

[Long code regarding range 3 of cells]

[Long code regarding range 4 of cells]
End sub
____________



What I want is the following:


________
Private Sub Worksheet_SelectionChange(ByVal target As Range)

[If user selects one cell in the range A1:A50 then call sub1]


[If user selects one cell in the range B1:B50 then call sub2]


[If user selects one cell in the range C1:CA50 then call sub3]


[If user selects one cell in the range D1:D50 then call sub4]


End sub

____________


Suggestions???


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



Reply
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
clean up code a little terilad Excel Discussion (Misc queries) 12 April 12th 10 07:35 PM
clean up data BNT1 via OfficeKB.com Excel Discussion (Misc queries) 1 February 14th 07 03:43 PM
Clean Up Code - consolidate steps Frantic Excel-er Excel Discussion (Misc queries) 6 June 30th 05 03:40 PM
Trim function doesn't clean out ASCII Code 160 (Space) Ronald Dodge Excel Worksheet Functions 6 January 27th 05 03:48 AM
=clean(a1) news.verizon.net Excel Programming 2 August 25th 03 11:08 PM


All times are GMT +1. The time now is 03:17 AM.

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"